matlab怎么把兩組數(shù)據(jù)畫在一起 怎么用matlab畫函數(shù)圖形?
怎么用matlab畫函數(shù)圖形?matlab的數(shù)據(jù)處理能力很強(qiáng)大,這款軟件還能繪制各種函數(shù)圖形。下面我將介紹用matlab畫函數(shù)圖形的方法,以在同一張圖上畫出y1sin(x)和y2sin^2(x)的圖形
怎么用matlab畫函數(shù)圖形?
matlab的數(shù)據(jù)處理能力很強(qiáng)大,這款軟件還能繪制各種函數(shù)圖形。下面我將介紹用matlab畫函數(shù)圖形的方法,以在同一張圖上畫出y1sin(x)和y2sin^2(x)的圖形為例。
工具/原料
matlab
1方法/步驟
輸入自變量:
畫已知的函數(shù)圖形,用向量的表示自變量比較方便。代碼為
xlinspace(0,8) % 用向量形式創(chuàng)建x。
2輸入因變量表達(dá)式:
y1sin(x) % 向量y1的值為x坐標(biāo)上某一x的s i n ( 2 x )值。
y2(sin(x)).^2 % 向量y2的值為( s i n ( x ) ) .^2,注意別忘記一點”.“
3 使用plot命令畫圖:
plot(x,y1)
4按回車,則畫出y1sin(x)的圖形。
如果這時直接繼續(xù)畫y2sin^2(x)的圖形,則在另一張圖中畫,為了在同一張圖中畫兩個函數(shù)圖,輸入下面代碼:
hold on
5再輸入繪圖命令:
plot(x,y2)
按回車,則在同一張圖上畫出了這兩個函數(shù)的圖形??梢酝ㄟ^菜單欄中的insert添加坐標(biāo)名稱,文本等。
其他函數(shù)的畫法類似!
matlab如何編輯數(shù)據(jù)?
1.
運(yùn)行MATLAB程序,點擊工具欄上的導(dǎo)入數(shù)據(jù)工具按鈕
2.
在彈出的“導(dǎo)入數(shù)據(jù)”對話框中找到前面保存的數(shù)據(jù)文件,“打開”
3.
此時xls文件在matlab中被打開
4.
在窗口工具欄左側(cè)導(dǎo)入選項中選擇“(矩陣)”,然后點擊工具欄右側(cè)的“勾”,導(dǎo)入數(shù)據(jù)
MATLAB中struct怎么構(gòu)成2×2?
使用struct函數(shù)創(chuàng)建結(jié)構(gòu)
使用struct函數(shù)也可以創(chuàng)建結(jié)構(gòu),該函數(shù)產(chǎn)生或吧其他形式的數(shù)據(jù)轉(zhuǎn)換為結(jié)構(gòu)數(shù)組。
struct的使用格式為:
s
sturct(field1,values1,field2,values2,…)//注意引號
該函數(shù)將生成一個具有指定字段名和相應(yīng)數(shù)據(jù)的結(jié)構(gòu)數(shù)組,其包含的數(shù)據(jù)values1、valuese2等必須為具有相同維數(shù)的數(shù)據(jù),數(shù)據(jù)的存放位置域其他結(jié)構(gòu)位置一一對應(yīng)的。對于struct的賦值用到了元胞數(shù)組。數(shù)組values1、values2等可以是元胞數(shù)組、標(biāo)量元胞單元或者單個數(shù)值。每個values的數(shù)據(jù)被賦值給相應(yīng)的field字段。
當(dāng)valuesx為元胞數(shù)組的時候,生成的結(jié)構(gòu)數(shù)組的維數(shù)與元胞數(shù)組的維數(shù)相同。而在數(shù)據(jù)中不包含元胞的時候,得到的結(jié)構(gòu)數(shù)組的維數(shù)是1×1的。例如:
s
struct(type,{big,little},color,{blue,red},x,{3,4})
s
1x2 struct array with fields:
type
color
x
得到維數(shù)為1×2的結(jié)構(gòu)數(shù)組s,包含了type、color和x共3個字段。這是因為在struct函數(shù)中{big,little}、{blue,red}和{3,4}都是1×2的元胞數(shù)組,可以看到兩個數(shù)據(jù)成分分別為:
s(1,1)
ans
type: big
color: blue
x: 3
s(1,2)
ans
type: little
color: red
x: 4
相應(yīng)的,如果將struct函數(shù)寫成下面的形式:
s
struct(type,{biglittle},color,{bluered},x,{34})
s
2x1 struct array with fields:
type
color
x
則會得到一個2×1的結(jié)構(gòu)數(shù)組。
下面給出利用struct構(gòu)建結(jié)構(gòu)數(shù)組的具體實例。
【例4.3.1-3】利用函數(shù)struct,建立溫室群的數(shù)據(jù)庫。
(1) struct預(yù)建立空結(jié)構(gòu)數(shù)組方法之一
a cell(2,3) % 創(chuàng)建2×3的元胞數(shù)組
green_house_1struct(name,a,volume,a,parameter,a(1,2))
green_house_1
2x3 struct array with fields:
name
volume
parameter
(2)struct預(yù)建空結(jié)構(gòu)數(shù)組方法之二
green_house_2struct(name,a,volume,[],parameter,[])
green_house_2
2x3 struct array with fields:
name
volume
parameter
(3)struct預(yù)建空結(jié)構(gòu)數(shù)組方法之三
green_hopuse_3(2,3)struct(name,[],volume,[],parameter,[])
green_hopuse_3
2x3 struct array with fields:
name
volume
parameter
(4)struct創(chuàng)建結(jié)構(gòu)數(shù)組方法之四
a1{六號房}a2{3200立方米}
green_house_4(2,3)struct(name,a1,volume,a2,parameter,[])
T6[31.2,30.4,31.6,28.729.7,31.1,30.9,29.6]
green_house_4(2,3).parameter.temperatureT6
green_house_4
ans
2x3 struct array with fields:
name
volume
parameter