how to plot the graph

5 visualizzazioni (ultimi 30 giorni)
mohd akmal masud
mohd akmal masud il 8 Ago 2024
Commentato: Star Strider il 8 Ago 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))

Risposta accettata

Star Strider
Star Strider il 8 Ago 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')
Uz = 1x1 cell array
{'name2.spe'}
A1 = readmatrix(Uz{1}, 'FileType','text')
A1 = 512x2
0.5000 0.4389 1.0000 0.4886 1.5000 0.5076 2.0000 0.5121 2.5000 0.5063 3.0000 0.4991 3.5000 0.4867 4.0000 0.4771 4.5000 0.4651 5.0000 0.4516
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x = A1(:,1);
y = A1(:,2);
figure
plot(x, y)
grid
T1 = readtable(Uz{1}, 'FileType','text')
T1 = 512x2 table
Var1 Var2 ____ _______ 0.5 0.43895 1 0.48862 1.5 0.5076 2 0.51209 2.5 0.50632 3 0.49912 3.5 0.48669 4 0.47707 4.5 0.46511 5 0.4516 5.5 0.43467 6 0.42078 6.5 0.4021 7 0.3875 7.5 0.37563 8 0.3562
x = T1{:,1};
y = T1{:,2};
figure
plot(x, y)
grid
.
  4 Commenti
mohd akmal masud
mohd akmal masud il 8 Ago 2024
Star Strider
Star Strider il 8 Ago 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.)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by