Code to import file

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 日
readmatrix() ?
Kimi Nina
Kimi Nina 2021 年 4 月 5 日
No i want the code to import a file that contains a matrix in order to draw a graph
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 日

0 投票

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.

質問済み:

2021 年 4 月 4 日

回答済み:

2021 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by