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

11 Ansichten (letzte 30 Tage)
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 Kommentare
Image Analyst
Image Analyst am 17 Jul. 2020
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Anmol Dhiman
Anmol Dhiman am 20 Jul. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by