フィルターのクリア

How can I store the output from a function to the workspace ?

2 ビュー (過去 30 日間)
Nour BS
Nour BS 2017 年 11 月 14 日
コメント済み: Nour BS 2017 年 11 月 15 日
Hi,
Help me to store the obtained output (minDist) in the workspace. You will find enclosed the function tsp_ga.m that I use.
Thanks in advance.
  2 件のコメント
James Tursa
James Tursa 2017 年 11 月 14 日
How are you currently calling this function?
Nour BS
Nour BS 2017 年 11 月 15 日
Actually, My main goal is to save the output (minDist) in a vector, therefore I used the loop "for" which runs the function tsp_ga.m n times. So to do it I wrote the following code (be n=5):
if kk=1:5
tsp_ga
ss(kk)=minDist
end
But it gave the following error: " Undefined function or variable 'minDist'. Error in (line 4) ss(kk)=minDist_ ". So I think I need to store the output "minDist" from the function to the workspace.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2017 年 11 月 15 日
編集済み: Stephen23 2017 年 11 月 15 日
The function tsp_ga returns a structure with lots of values in it. minDist is one of those values:
S = tsp_ga(...)
S.minDist
Or inside your loop:
if kk=1:5
S = tsp_ga(...);
ss(kk) = S.minDist;
end
This is explained quite well inside the function help, with both calling syntax and examples. You should read the help of every function that you use, because the help shows you how to use that function, and means that you do not have to guess and waste your time asking random strangers on the internet for help.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by