How do i know to which graph i'm plotting?

data1 = load('data1.mat')
data2 = load('data2.mat')
by doing `plot(val(1, :))` i have a graph but I don't know if it corresponds to data 1 or data 2 how can I choose the data in plots?
the second question is how can I concatenate data1 and data 2 basically let's say data1 is 1 2 3 and data2 is 4 5 6 the expected outcome would be :
1 2 3
4 5 6
then plot them both in the same figure?

Antworten (3)

Nesha Wright
Nesha Wright am 20 Jul. 2018

0 Stimmen

To concatenate then use the command 'cat', to plot both 'plot(catdata)' or use the command 'hold on' if you decide not to concatenate them but still want to plot both.

1 Kommentar

Elias Unk
Elias Unk am 20 Jul. 2018
Bearbeitet: Elias Unk am 20 Jul. 2018
I want to draw the content of data1 and data2 on the same figure

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 20 Jul. 2018

0 Stimmen

I think you missed a line of code connecting data1 and data2 to val ?
For your other part:
combined = [data1; data2];
plot(combined.')
When you ask to plot a 2D array, plot() prefers to plot by column. Your combined would have three columns, so if you had done
plot(combined)
you would get three lines.
I say "prefers" to plot by columns because when you pass an x, y pair,
plot(x, combined)
then if x is a vector then x and y will be automatically transposed if needed so that size(x,1) = size(y,1). For example, plot(1:3, combined) would notice that x was length 3 and would automatically transpose combined to match.

4 Kommentare

Elias Unk
Elias Unk am 20 Jul. 2018
Bearbeitet: Elias Unk am 20 Jul. 2018
Plotting combined gave this error >> plot(combined.') Error using plot Not enough input arguments. and i can simply do this:
plot(data.val(1,:));hold on; plot(data2.val(1,:))
but what if i have 15 graphs i just want a methods that draws all the graphs in a matrix
What shows up for
class(combined)
size(combined)
which plot(combined)
Elias Unk
Elias Unk am 20 Jul. 2018
Bearbeitet: Elias Unk am 20 Jul. 2018
In order:
struct
2 1
built-in (C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\matlab\graph2d\plot)
Try
combined = [data1.data1; data2.data2];

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 21 Jul. 2018

0 Stimmen

If you assigned data1 to val, then plotting val would plot data1. If you assigned data2 to val, then plotting val would plot data2.
To plot both data1 and data2 on the same axes:
plot(data1, 'b*-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
hold on;
plot(data2, 'rs-', 'LineWidth', 2, 'MarkerSize', 10);
xlabel('Index', 'FontSize', 20);
ylabel('Value'FontSize', 20);

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 20 Jul. 2018

Kommentiert:

am 21 Jul. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by