how do you write a conditional struct?

how do you write a conditional struct?

1 件のコメント

Walter Roberson
Walter Roberson 2013 年 11 月 18 日
What is a "conditional struct" ?

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

 採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 18 日

1 投票

At the beginning start with
data = [];
Then, in each of the error cases, after you disp() the string, add
return
before the "end" of the "if"
if condition
disp('message')
return
end

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 18 日

0 投票

Maybe you are asking about if/elseif/else

4 件のコメント

vishant m.
vishant m. 2013 年 11 月 18 日
i tried using if, but it doesnt work :( can you give a simple example
Matt J
Matt J 2013 年 11 月 18 日
編集済み: Matt J 2013 年 11 月 18 日
@vishant
Why don't you give an example of what doesn't work and describe what you want to happen instead.
vishant m.
vishant m. 2013 年 11 月 18 日
編集済み: Azzi Abdelmalek 2013 年 11 月 18 日
function data=test3(n)
if isnumeric(n)==0;
n=([1 2 3 4]); display('input has two many terms or is not a vector');
end
if isvector(n)==0;
n=([1 2 3 4]); display('input has two many terms or is not a vectorl');
end
x=linspace(-5,5,1000);
y=polyval(n,x);
plot(x,y);
q=roots(n);
data=plot(q(imag(q)==0), zeros(sum(imag(q)==0)),'r+');
data= struct('x',x,'p',n,'rp',q,'rpp',q(imag(q)==0),'px',(x));
end
this is the code, you can see the struct. there are 2 if functions at the start, i need the struct to give ans[] when the condition of any of the ifs applies.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 18 日
[i need the struct to give ans[] when the condition of any of the ifs applies.] I can't understand what you mean

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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by