Plot Matrices stored in Cell Array

6 Ansichten (letzte 30 Tage)
shahzer rahman
shahzer rahman am 7 Mär. 2020
Bearbeitet: Ameer Hamza am 7 Mär. 2020
I have a 1by2 cell array that has the following elements
C{1}= [ 1 2 3 4 5 6]
C{2}= [987 877 77 666 777 66 77 ]
I want to plot these matrices C{1} and C{2} on the same graph.
Pleas help.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 7 Mär. 2020
You can plot elements of a cell array on the same graph by holding the axes. For example,
C{1} = [1 2 3 4 5 6];
C{2} = [987 877 77 666 777 66 77];
fig = figure();
ax = axes();
hold(ax);
for i = C
plot(i{:});
end
  7 Kommentare
shahzer rahman
shahzer rahman am 7 Mär. 2020
How do I find the index of the last element of each cell ?
For example; C{1}= [1 2 3 4 5 6]; and C{2} = [987 877 77 666 777 66 77];
I need the index of 6 from C{1} and that of 77 from C{2}.
expected answer,
index_end_C1=6
index_end_C2=7
Ameer Hamza
Ameer Hamza am 7 Mär. 2020
Bearbeitet: Ameer Hamza am 7 Mär. 2020
You can get the index of last element using this
cellfun(@(x) numel(x), C)

Melden Sie sich an, um zu kommentieren.

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