フィルターのクリア

plot each line in a matrix

89 ビュー (過去 30 日間)
Iman Hana Mustafa Kamal
Iman Hana Mustafa Kamal 2019 年 3 月 1 日
コメント済み: dpb 2019 年 3 月 1 日
I am trying to plot each line in sw matrix. so there will be 16 line plot in the same graph.
the rows from each matrix needs to be the y axis
x axis is time. (t = linspace (0:0.4:4))
sw is a 16x10 double matrix
plot (t,sw)

回答 (1 件)

dpb
dpb 2019 年 3 月 1 日
plot (t,sw.')
Just transpose the array to use plot()'s builtin facility to plot each column as a variable.
It's the power of the matrix-orientation of Matlab syntax; just have to think about how to apply it to your given problem.
Or, of course, rethink your data orientation to use the Matlab convention of columns being the variables and rows the observations and not have to do anything different.
  2 件のコメント
Iman Hana Mustafa Kamal
Iman Hana Mustafa Kamal 2019 年 3 月 1 日
I tried aplying the code that you gave, it did not work. I think what you meant here is not what i tried to do - "Just transpose the array to use plot()'s builtin facility to plot each column as a variable."
I want to plot the 16 line graphs in the same plot from the 16x10 matrix, as the y axis. For the y axis, it's the "t" which has size of 1x10 matrix.
Thank you!
dpb
dpb 2019 年 3 月 1 日
"Show your work!"
If the problem is as you described, it will "work".
t=linspace(0,4,10).'; % your t in correct syntax
x=randn(16,10); % make a data array of your given size
y=10:10:160; % we'll make so can tell "who's who in the zoo!"
z=bsxfun(@plus,x,y.'); % by adding 10 to each of the row means
figure
plot(t,z.') % and plot the transposed array, z
which yielded the following figure:
untitled.jpg
where you can see the 16 lines and each has a mean offset by 10.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by