Code to import file

조회 수: 2 (최근 30일)
Kimi Nina
Kimi Nina 2021년 4월 4일
답변: Walter Roberson 2021년 4월 5일
How do i import a file that contains matrix to draw a graph please ? I want to do it with a code?
  댓글 수: 4
Walter Roberson
Walter Roberson 2021년 4월 5일
filename = 'test.txt';
%part 1: create some demonstration data to work with
s = randi(9, 15, 1);
t = randi(9, 15, 1);
writematrix([s,t], filename);
%part 2: read the demonstration data:
st = readmatrix(filename);
s = st(:,1);
t = st(:,2);
%part 3: create the graph:
G = graph(s, t);
%part 4: draw the graph:
plot(G)
It look s to me as if readmatrix() does in fact work.
Kimi Nina
Kimi Nina 2021년 4월 5일
Thank you sooo soo much you saved me

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 4월 5일
filename = 'test.txt';
%part 1: create some demonstration data to work with
s = randi(9, 15, 1);
t = randi(9, 15, 1);
writematrix([s,t], filename);
%part 2: read the demonstration data:
st = readmatrix(filename);
s = st(:,1);
t = st(:,2);
%part 3: create the graph:
G = graph(s, t);
%part 4: draw the graph:
plot(G)
It looks to me as if readmatrix() does in fact work.

카테고리

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