How to I plot a graph from this data

19 vues (au cours des 30 derniers jours)
Nathan
Nathan le 7 Oct 2025 à 17:28
Commenté : Star Strider le 7 Oct 2025 à 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.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by