error checking in matlab

5 ビュー (過去 30 日間)
Sam
Sam 2012 年 11 月 20 日
I have a code segment where I am error checking input arguments and I am having issues making it work... the structure for the code for the two error checks are the following:
error code should be m>n or n<1 and xi=xj for i!=j
if (m>n)||(n<1)
error('myApp:argChk', 'check for correctness of input')
end
for i = 1:n
for j = i+1:m
if x(i,1)=x(j,1)
error('myApp:argChk', 'check for correctness of input')
end
end
end

回答 (1 件)

Matt Fig
Matt Fig 2012 年 11 月 20 日
編集済み: Matt Fig 2012 年 11 月 20 日
When asking a question, you need to explain what you post. What is m and n? Are they supposed to be the size of x, like:
[m,n] = size(x)
or what? Are they passed in or calculated in your function?
There is an error on this line:
if x(i,1)=x(j,1)
it should read:
if x(i,1)==x(j,1)
Please be more specific about what you want to do. This statement:
x(ii) must be equal to x(jj) for ii~=jj
doesn't make much sense. Do you mean:
x(ii,jj) must be equal to x(jj,ii) for ii~=jj
What about non-square matrices?

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by