Borrar filtros
Borrar filtros

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

22 visualizaciones (últimos 30 días)
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 comentarios
Image Analyst
Image Analyst el 17 de Jul. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Anmol Dhiman
Anmol Dhiman el 20 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by