MATLAB Answers

How to manipulate cell array of vectors (just numbers ) that are not same length?

2 ビュー (過去 30 日間)
Ole
Ole 2016 年 3 月 25 日
編集済み: Image Analyst 2016 年 3 月 25 日
I want to plot cell array M{k} that has vectors of different size. How to do it ?
How to transpose it ?
plot(M{:}) returns error.
M{k}
[1, 2]
[1,3 , 5]
[1,3,5,6,7]
[1]
etc..

  2 件のコメント

John BG
John BG 2016 年 3 月 25 日
can you attach the cell or a sample so readers can try to answer your question?
James Tursa
James Tursa 2016 年 3 月 25 日
How are you envisioning that this data should look like on the plot? I.e., if you weren't getting an error, what would you expect the plot to look like? What points or lines would be there for your representative data above?

サインイン to comment.

回答 (2 件)

Stalin Samuel
Stalin Samuel 2016 年 3 月 25 日
  • Your file has a cell array which contains different length data in each cell
  • if you wants to plot a specific cell data you can use the below code
plot(cell2mat(M1(1,100)))% to plot data in 100th cell

  0 件のコメント

サインイン to comment.


Image Analyst
Image Analyst 2016 年 3 月 25 日
編集済み: Image Analyst 2016 年 3 月 25 日
Try this:
M={[1, 2]
[1,3 , 5]
[1,3,5,6,7]
[1]}
for k = 1 : length(M)
M{k}
plot(M{k}, 'b*', 'MarkerSize', 13, 'LineWidth', 2);
hold on;
end
grid on;
xlabel('Index', 'fontSize', 20);
ylabel('Value', 'fontSize', 20);
If you want, you could plot each cell in a different color, like
plot(M{k}, 'b*', 'MarkerSize', 13, 'LineWidth', 2, 'Color', rand(1,3));

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by