how to plot the graph
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mohd akmal masud
le 8 Août 2024
Commenté : Star Strider
le 8 Août 2024
Hello Everyone,
I have some data as attached. Then I have the code to plot the graph. But I have to convert my file to excel first.
Anyway have that I can plot grpah wothout convert my file to excel?
clc
clear all
close all
spec=readlines('nema2.spe'); % read as text
whos spec
data=readmatrix('nema2.spe.xlsx'); %the data from point1.prn must export to excel first.
whos data
%then from excel, it can be plotted.
plot(data(:,1),data(:,2))
0 commentaires
Réponse acceptée
Star Strider
le 8 Août 2024
There is no need to convert it to Excel. It is only necessary to tell readmatrix (introduced in R2019a) that it is a text file, since that is not obvious from the file extension. Otherwise, readtable (inttroduced in R2013b) will work, with a minor modification to the readmatrix code.
Try this —
Uz = unzip('name2.zip')
A1 = readmatrix(Uz{1}, 'FileType','text')
x = A1(:,1);
y = A1(:,2);
figure
plot(x, y)
grid
T1 = readtable(Uz{1}, 'FileType','text')
x = T1{:,1};
y = T1{:,2};
figure
plot(x, y)
grid
.
4 commentaires
Star Strider
le 8 Août 2024
@mohd akmal masud — As always, my pleasure!
To add axis labels to a 2D plot, use xlabel and ylabel, and to add a title, use title. (There are similar functions for 3D plots and groups of plots such as those produced by the tiledlayout function.)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!