필터 지우기
필터 지우기

I have a cell array and want to plot each of the cells on a tiled layout.

조회 수: 22 (최근 30일)
I have a cell array which contains nx2 matricies in each cell. I'm trying to figure out how to plot each of those cells (x vs y) in a loop. Any ideas?
This is what I have:
numColmns = size(Data, 2);
for i = 1:2:numCols-1
A{i} = Data(:, i:i+1);
end
B = A(:, 1:2:end); %removes empty cells in cell array A
numPlots = length(B); %number of plots to make
tiledlayout(numPlots,1) %total number of plots in a row by 1 column
%insert loop where it automatically plots all cells in B
B gives me B{1}, B{2}, ... , B{n}, etc.
  댓글 수: 2
Image Analyst
Image Analyst 2020년 7월 17일
So "A" is your cell array, but what is Data? Give an example of Data, either in a .mat file or with code to generate it.
And what is tiledlayout()? Is that a function you're supposed to build that uses plot()? How many plots do you want? Each curve in a separate plot (using the subplot() function), or all curves on the same plot?

댓글을 달려면 로그인하십시오.

채택된 답변

Anmol Dhiman
Anmol Dhiman 2020년 7월 20일
Hi Khiana,
You can use the below code
A_new ={}; % Cell array declared as A in your code
numColmns = size(A, 2);
for i = 1:2:numColmns-1
A_new{i} = A(:, i:i+1);
end
B = A_new(:, 1:2:end); %removes empty cells in cell array A
numPlots = length(B); %number of plots to make
tiledlayout(numPlots,1) %total number of plots in a row by 1 column
for i = 1: numPlots
a = B{i}';
nexttile
plot(a(1,:),a(2,:))
end
Regards,
Anmol Dhiman

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by