How to set() plot in matlab with cell array
조회 수: 27 (최근 30일)
이전 댓글 표시
Hello, ive been trying to set a plots xAxis and yAxis so it plots my cell array.
cellArray = {1,4}. cellArray has 4 cells and each cell is a 1024X1 array.
Ive tried
set(hPlot3, 'Xdata',1:1024,'Ydata',[cellArray(:)]);
And tried setting cell array to matrix and plotting:
A = cell2mat(cellArray);
set(hPlot3, 'Xdata',1:1024,'Ydata',A);
But both have error'Value must be a vector of numeric type'.
I tried looking up setting a plot with cell arrays involved but didnt find anything.
I know this is simple fix but am having a very hard time with it.Apologies.
using this allows me to plot 1 cell but not all:
set(hPlot3, 'Xdata',1:1024','Ydata',cellArray{1,1}(:));
댓글 수: 0
답변 (2개)
Amit
2020년 1월 16일
This should work, I think you had missed the transpose of x-array:
A = cell2mat(cellArray);
set(hPlot3, 'Xdata',1:1024','Ydata',A);
Walter Roberson
2020년 1월 17일
You cannot do that. When you have multiple lines to plot then each of them must have its own line object
h = plot(x, y_with_multiple_columns)
will give you back an array of line objects, one for each column of y. You would then set() the YData of each of the handles individually.
There is an obscure way to set multiple properties for multiple handles, but you probably should not be using it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!