Effacer les filtres
Effacer les filtres

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

22 vues (au cours des 30 derniers jours)
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 commentaires
Image Analyst
Image Analyst le 17 Juil 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?
Fangjun Jiang
Fangjun Jiang le 17 Juil 2020
Note A{2}, A{4},... are empty

Connectez-vous pour commenter.

Réponse acceptée

Anmol Dhiman
Anmol Dhiman le 20 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by