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

David Hill
David Hill 2021년 2월 16일
Show us your code
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일

0 개 추천

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

AKSHAY DESHMUKH
AKSHAY DESHMUKH 2021년 2월 17일
편집: AKSHAY DESHMUKH 2021년 2월 17일
Altitude = [10000,5000,6000];
Mach = [0.8,1,1.2];
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
After Using this again the workspace shows the result for only last comination. I want workspace to show the results for all the combinations separately.
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개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by