How to use one conditions's result in to another condition?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello. I am facing some problem with Matlab coding. I want:
if working_mode == 1
a = func_con(x);
save a;
else %%%Here, i want to use the value of "a"
a;
for i = 1:3
if a > 10
a = func_rep(a);
else break,
end
a;
end
end
How can i perform this operation? Any help will be appreciated. Thanks.
0 件のコメント
回答 (2 件)
Friedrich
2012 年 2 月 15 日
Hi,
if a doesnt exist than you cant use it. But you can use ifempty to check if the variable a is filled with data, e.g.
a = [];
if working_mode == 1
a = func_con(x);
save a;
else %%%Here, i want to use the value of "a"
if ~isempty(a)
a;
for i = 1:3
if a > 10
a = func_rep(a);
else break,
end
a;
end
else
disp('a doesnt contain data')
end
end
2 件のコメント
Friedrich
2012 年 2 月 15 日
You have to declare a like i did. the variable a must be known. So write a = [] somewhere at the beginning of your code.
David
2012 年 2 月 15 日
You can also use
exist(a,'var')
to check if a variable exists in the current workspace
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!