aa = {rand(482,5) , rand(493,5)};
t = linspace(0, 20,975 ); % Generating Time Vector Series
Now how can I plot the cell data "aa" while keeping Time vector Series will lie in the X-axis?
Thanks in ADVANCE !!

 Réponse acceptée

Voss
Voss le 3 Juin 2022
aa = {rand(482,5) , rand(493,5)};
t = linspace(0, 20,975 ); % Generating Time Vector Series
n_aa = cellfun(@(x)size(x,1),aa)
n_aa = 1×2
482 493
plot(t(1:n_aa(1)),aa{1})
hold on
plot(t(n_aa(1)+(1:n_aa(2))),aa{2})

4 commentaires

Thank you for the answer.
But what will happen if I have the cell array, aa ={ 3 or more cell }. Then How I shall plot?
plot(t(1:n_aa(1)),aa{1})
hold on
plot(t(n_aa(1)+(1:n_aa(2))),aa{2})
% this time, I'll start with n_aa
n_aa = randi([480 500],1,7)
n_aa = 1×7
481 488 490 489 500 489 497
% and generate random aa from n_aa
aa = arrayfun(@(x)rand(x,5),n_aa,'UniformOutput',false)
aa = 1×7 cell array
{481×5 double} {488×5 double} {490×5 double} {489×5 double} {500×5 double} {489×5 double} {497×5 double}
% t is defined as before (but with more elements)
t = linspace(0, 20, sum(n_aa));
% generate t_idx to help with plotting
t_idx = cumsum([0 n_aa])
t_idx = 1×8
0 481 969 1459 1948 2448 2937 3434
% plot in a loop this time
hold on
for ii = 1:numel(aa)
plot(t(t_idx(ii)+1:t_idx(ii+1)),aa{ii})
end
Amit Chakraborty
Amit Chakraborty le 3 Juin 2022
Thank you very much !
Voss
Voss le 3 Juin 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by