I need to plot each cell in a 1x7 cell - each has a 2x15 double. I need them all on the same graph, just as different lines. So trac_speed{1} would be plotted with the first row on the x axis and second row on the y axis, and trac_speed{2} is a seperate line on the same plot. How can I do this?
I used the following code to generate the 1x7 cell:
n=length(total_ratios);
trac_speed = cell(n:1);
for i = 1:n
trac_speed{i} = [(60*2*pi*r/(1609.344*total_ratios(i)))...
*Torque(1, 1:length(Torque)); (total_ratios(i)*0.224809/r)*...
Torque(2, 1:length(Torque))];
end

 Respuesta aceptada

David Rogers
David Rogers el 30 de Abr. de 2019

1 voto

figure;
hold on;
for i = 1:length(trac_speed)
plot(trac_speed{i}(1, 1:15), trac_speed{i}(2, 1:15))
end

Más respuestas (1)

Adam Danz
Adam Danz el 30 de Abr. de 2019
Editada: Adam Danz el 30 de Abr. de 2019

0 votos

Here's an alternative (without loops)
figure
hold on
cellfun(@(x)plot(x(1,:),x(2,:)), trac_speed)
Demo:
% Create fake data
trac_speed = cellfun(@(x)[1:15; rand(1,15)], cell(1,7),'UniformOutput', false);
figure
axes
hold on
h = cellfun(@(x)plot(x(1,:),x(2,:)), trac_speed);
legendTxt = strsplit(sprintf('line %d|', 1:numel(h)),'|');
legend(h, legendTxt(1:end-1))

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 30 de Abr. de 2019

Editada:

el 30 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by