How to I plot a graph from this data

19 Ansichten (letzte 30 Tage)
Nathan
Nathan am 7 Okt. 2025 um 17:28
Kommentiert: Star Strider am 7 Okt. 2025 um 18:33
I have been trying to plot VPV by Depth in the code below:
A= readtable("PREM.txt");
Radius = A(:,1);
Density= A(:,2);
VPV= A(:,3);
VSV= A(:,4);
QK= A(:,5);
QMu= A(:,6);
VPH= A(:,7);
VSH= A(:,8);
eta= A(:,9);
Depth=Radius./6371;
However when I go to use the code plot(VPV,Depth), Matlab responds with:
>> plot(VPV,Depth)
%Red text from below this point
Error using plot
Invalid subscript for Y. A table variable
subscript must be a numeric array containing
real positive integers, a logical array, a
character vector, a string array, a cell array
of character vectors, or a pattern scalar used
to match variable names.
I don't know how to colour the text red so sorry for the confusion if the text colour causes any. If I could receive any help on this matter that would be appreciated.

Akzeptierte Antwort

Star Strider
Star Strider am 7 Okt. 2025 um 17:46
Use curly braces {} to get datafrom a table --
Radius = A{:,1};
Density= A{:,2};
VPV= A{:,3};
VSV= A{:,4};
QK= A{:,5};
QMu= A{:,6};
VPH= A{:,7};
VSH= A{:,8};
eta= A{:,9};
That should work.
.
  2 Kommentare
Nathan
Nathan am 7 Okt. 2025 um 18:32
Yes that made it able to plot the graph.
Thank you for your help!
Star Strider
Star Strider am 7 Okt. 2025 um 18:33
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Tags

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by