필터 지우기
필터 지우기

how to plot the graph

조회 수: 51 (최근 30일)
mohd akmal masud
mohd akmal masud 2024년 8월 8일 2:58
댓글: Star Strider 2024년 8월 8일 10:55
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))

채택된 답변

Star Strider
Star Strider 2024년 8월 8일 3:14
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
mohd akmal masud
mohd akmal masud 2024년 8월 8일 8:39
Star Strider
Star Strider 2024년 8월 8일 10:55
@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.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by