フィルターのクリア

How to write a row of a matrix using if statement?

3 ビュー (過去 30 日間)
Heya :)
Heya :) 2020 年 11 月 7 日
回答済み: dpb 2020 年 11 月 7 日
I have a Matrix M :-
M= (A B)
A=1+x1+y1+x1y1
and
B=1+x2+y2+x2y2
How to write the B using if statement? Below is my code where i write A but don't know how to continue with B. Please help.
M=zeros([100,10]);
for i=1:100
for j=1:20
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x(i);
elseif j==3
M(i,j)=y(i);
elseif j==4
M(i,j)=x(i)*y(i);
After this how to add B?

採用された回答

dpb
dpb 2020 年 11 月 7 日
A=[ones(size(x1) x1 y1 x1.*y1];
B=[ones(size(x2) x2 y2 x2.*y2];
M=[A B];
Of course, numel(x1)==numel(x2) or all goes boom!

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by