Filter löschen
Filter löschen

How to plot specific data from a imported matrix?

35 Ansichten (letzte 30 Tage)
Hans Lipton
Hans Lipton am 1 Nov. 2021
Kommentiert: Hans Lipton am 1 Nov. 2021
Good day all,
Maybe some basic stuff, but I need support on following situation:
I used [data] = xlsread('testfile.xlsx') to import data from excel in order to create a matrix. See image.
Now I would like to plot the data into a 2D-diagram. So x will the first column and y the second column. How can I separately plot for example the data from row 2 to 5 into a diagram. Many thanks for your support.

Akzeptierte Antwort

Dave B
Dave B am 1 Nov. 2021
Bearbeitet: Dave B am 1 Nov. 2021
You can plot all data with a line plot using
plot(data(:,1),data(:,2))
You can plot all data with a scatter plot using
scatter(data(:,1),data(:,2))
You can make a line plot of rows 2 to 5
plot(data(2:5,1),data(2:5,2))
or scatter:
scatter(data(2:5,1),data(2:5,2))
Note: xlsread is not recommended. The documentaiton recommends using readtable, readmatrix, or readcell instead.
For more on indexing into arrays:
For more types of plots:
  4 Kommentare
Dave B
Dave B am 1 Nov. 2021
This is a MATLAB data type known as a cell array, it's a sort-of old fashioned way to store text. Note that the brackets aren't really part of the text, they're just indicating the way the data are stored (and how you'd access it).
Either way, strings are way better than cells (IMO) and the brackets disappear when you use strings. You can convert after reading it in:
T.Name = string(T.Name)
Or read in those chars directly as a strings:
T = readtable(yourfile, 'TextType', 'string')
Hans Lipton
Hans Lipton am 1 Nov. 2021
Many thanks again, this a very helpful support.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by