フィルターのクリア

Receiving two outputs in function

2 ビュー (過去 30 日間)
Sharanya
Sharanya 2022 年 12 月 10 日
回答済み: Stephan 2022 年 12 月 10 日
I want both the nodeCrd and edgeList to display, but I'm only able to get the first one listed to display.
function [nodeCrd,edgeList]=ReadInputData()
filename="inputdataa.txt";
fileId = fopen(filename,"r");
if (fileId == -1)
disp("Could not open the file !")
return
end
% read the first line
tempLine = fgetl(fileId);
disp(tempLine)
% read the second line
tempLine = fgetl(fileId);
disp(tempLine)
% there is a pattern here (node's coordinates + IsSupport)
data = textscan(fileId,"%f %f %f %f %f %d");
% convert it to array
nodeCrd = cell2mat(data(1:5));
% pattern is finished at this line
% let's read that line
tempLine = fgetl(fileId);
disp(tempLine)
% there is another pattern here (memebrs)
data = textscan(fileId,"%f %f %f" );
% convert it to array
edgeList = cell2mat(data);
end

回答 (1 件)

Stephan
Stephan 2022 年 12 月 10 日
To get multiple outputs from a function, you have to call it with multiple output arguments:
[MY_nodeCrd,MY_edgeList]=ReadInputData()

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by