how can i write if condition for an empty array?

Following is the code:
clc
A=[333.3333 -333.3333 0;333.3333 666.6667 -333.3333;0 -333.3333 333.3333]
F=[0;0;10]
o=[]
%B=[1,o]
n1=input('Boundry Condition for N1')
n2=input('Boundry Condition for N2')
B=[n1,n2]
if n1==1 & n2==o;%1=fixed & o=free, but cant read this after running file
c=2
d=n
disp('Loop 1')
elseif n1==o & n2==1;
c=1
d=n-1
disp('Loop 2')
else n1==1 & n2==1;
c=2
d=n-1
disp('Loop 3')
end
AuxEqn=A(B,c:d)
AuxRHs=F(B)
A(B,:)=[];
A(:,B)=[]
F(B)=[]
U=inv(A)*F
R=AuxEqn*U

 採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 15 日

1 投票

You cannot compare [] to anything. Use isempty() to test for empty matrix.

4 件のコメント

Adi
Adi 2017 年 11 月 17 日
Ok thank you.
Adi
Adi 2017 年 11 月 17 日
I tried using isempty() but its again showing error, I cant figure out how to incorporate this in my if statement. I would highly appreciate If you can check my code. Regards
Walter Roberson
Walter Roberson 2017 年 11 月 17 日
編集済み: Walter Roberson 2017 年 11 月 17 日
if n1==1 && isempty(n2);
c=2
d=n
disp('Loop 1')
elseif isempty(n1) && n2==1
c=1
d=n-1
disp('Loop 2')
else n1==1 && n2==1;
c=2
d=n-1
disp('Loop 3')
else
disp('Something else!')
end
Adi
Adi 2017 年 11 月 19 日
編集済み: Adi 2017 年 11 月 19 日
@Walter Roberson: This has solved my Problem Thank you so much.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

Adi
2017 年 11 月 15 日

編集済み:

Adi
2017 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by