필터 지우기
필터 지우기

How to use one conditions's result in to another condition?

조회 수: 1 (최근 30일)
Ayesa
Ayesa 2012년 2월 15일
편집: Azzi Abdelmalek 2013년 10월 13일
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.

답변 (2개)

Friedrich
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
Ayesa
Ayesa 2012년 2월 15일
Thanks for your reply. I tried as you suggested. After saving "a", i wrote "ee = ~isempty(a);"
After running, i got:
ee = 1;
??? Undefined function or variable "a".
Error in ==> calcperf at 154
if ~isempty(a)
Can you please suggest me how to solve the problem? Thanks.
Friedrich
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
David 2012년 2월 15일
You can also use
exist(a,'var')
to check if a variable exists in the current workspace

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by