Combinations running through for loop

11 ビュー (過去 30 日間)
AKSHAY DESHMUKH
AKSHAY DESHMUKH 2021 年 2 月 16 日
コメント済み: AKSHAY DESHMUKH 2021 年 2 月 17 日
I have written the code for generating combinations for the given set of data and then each combination goes through code using for loop. However, after running code for each combination I can see the output for only the last combination in the workspace.
  3 件のコメント
AKSHAY DESHMUKH
AKSHAY DESHMUKH 2021 年 2 月 17 日
編集済み: AKSHAY DESHMUKH 2021 年 2 月 17 日
function [Result] = Untitled2(Altitude,Mach)
for Alti = 1:length (Altitude)
A= Altitude(Alti);
for Velo= 1:length(Mach)
B=Mach(Velo);
disp(A);
disp(B);
Result = A+B;
disp(Result);
end
end
end
AKSHAY DESHMUKH
AKSHAY DESHMUKH 2021 年 2 月 17 日
Worspace only displays output for last combination

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

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 17 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 17 日
Because it is a function file, the output arguments only reflects in the workspace
function [.....]=fun_name(.....)
%.........^ Output Arguments
end
Or
Define all varibles in the output arguments lists, which you wish to reflects in the workspace
function [Result,B]=fun_name(.....)
%.........^ Output Arguments
end
Or Try with without function file
Altitude=...?
Mach=.....?
for Alti = 1:length (Altitude)
A= Altitude(Alti);
for Velo= 1:length(Mach)
B=Mach(Velo);
disp(A);
disp(B);
Result = A+B;
disp(Result);
end
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 17 日
Store in an array
Result=zeros(1,length(Mach))
for Velo= 1:length(Mach)
B=Mach(Velo);
Result(Velo)= A+B;
disp(Result);
.....
end
AKSHAY DESHMUKH
AKSHAY DESHMUKH 2021 年 2 月 17 日
Perfect!!! That works

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by