How to scatter/plot a vector vs a cell array ?

Hello,
I have a vector w such that
w=0:0.1:5
I use this vector to get values saved in a cell array. such that for each element of w, I get 1,2, or 3 values stored in one cell as a vector.
as an example:
w=[0, 0.1, 0.2, 0.3, ....]
cellArray= {[3, -4, 5], [1], [-2], [3,3], ...}
I want to plot this such that w is the x axis and the corresponding values on the y axis?

4 件のコメント

Ahmed Anas
Ahmed Anas 2020 年 3 月 12 日
What you want is at x=0 , y varies at 3, -4 , 5 , at x= 0.1 y =1, at x=0.2, y=-2, and so on
and you want to plot all these on the same figure?
Nora Khaled
Nora Khaled 2020 年 3 月 12 日
Yes, this how I want to do it.
x=0, y=3, -4 , 5 it should be 3 points on the same graph.
x=0.1, y=1
..
Ahmed Anas
Ahmed Anas 2020 年 3 月 12 日
編集済み: Ahmed Anas 2020 年 3 月 12 日
clc
clear all
w=[0, 0.1, 0.2, 0.3]
cellArray= {[3, -4, 5], [1], [-2], [3,3]}
X=0;
t(1)=1;
for i=2:size(cellArray,2)
t(i)=t(i-1)+size(cell2mat(cellArray(i-1)),2);
end
for i=1:size(cellArray,2)
y=X;
X=size(cell2mat(cellArray(i)),2);
X=y+X;
G(i)=X;
end
for i=1:size(cellArray,2)
New_X_Matrix(t(i):G(i))=w(i);
end
New_X_Matrix=New_X_Matrix
New_Y_Matrix=cell2mat(cellArray)
plot(New_X_Matrix,New_Y_Matrix,'ro-','linewidth',2)
Check this code, it will work accordingly and hope you will understand this, it is somehow generalized code.
New_X_Matrix is your desired x matrix
New_Y_Matrix is the y coordinates matrix
Nora Khaled
Nora Khaled 2020 年 3 月 15 日
Thank you so much!
The code works perfectly.

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

 採用された回答

Adam Danz
Adam Danz 2020 年 3 月 12 日

0 投票

w=[0, 0.1, 0.2, 0.3];
cellArray= {[3, -4, 5], [1], [-2], [3,3]};
figure()
hold on % important
arrayfun(@(i)plot(w(i),cellArray{i}, '-o'), 1:numel(w))

3 件のコメント

Fego Etese
Fego Etese 2020 年 3 月 13 日
Hello Adam Danz, sorry to call your attention like this but I'm in dire need of help at the moment. Please help me with this cross correlation question.
Thank you
Nora Khaled
Nora Khaled 2020 年 3 月 15 日
Thank you so much!
Adam Danz
Adam Danz 2020 年 3 月 15 日
Glad I could help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 3 月 12 日

コメント済み:

2020 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by