How to I plot a graph from this data

19 views (last 30 days)
Nathan
Nathan on 7 Oct 2025 at 17:28
Commented: Star Strider on 7 Oct 2025 at 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.

Accepted Answer

Star Strider
Star Strider on 7 Oct 2025 at 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 Comments
Nathan
Nathan on 7 Oct 2025 at 18:32
Yes that made it able to plot the graph.
Thank you for your help!
Star Strider
Star Strider on 7 Oct 2025 at 18:33
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!