Write results in Excel under multiple If statements

1 回表示 (過去 30 日間)
gsourop
gsourop 2019 年 3 月 14 日
編集済み: Alex Mcaulley 2019 年 3 月 14 日
Hi there,
I would like to ask how can I use multiple if statements. I have written the following code but I only get results for the first if statements.
for j = 1 : 2
x = randn(10,1)
for k=1:2
y = randn(10,1)
if j == 1 & k == 1
xlswrite('Test.xls', [x y], 'Test1', 'b2');
if j == 1 & k == 2
xlswrite('Test.xls', [x y], 'Test1', 'p2');
if j == 2 & k == 1
xlswrite('Test.xls', [x y], 'Test1', 'b20');
if j == 2 & k == 2
xlswrite('Test.xls', [x y], 'Test1', 'p20');
end
end
end
end
end
end
I would appreciate any help. Thank you.

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 3 月 14 日
編集済み: Alex Mcaulley 2019 年 3 月 14 日
You need to close every if statement:
for j = 1 : 2
x = randn(10,1);
for k=1:2
y = randn(10,1);
if j == 1 && k == 1
xlswrite('Test.xls', [x y], 'Test1', 'b2');
end
if j == 1 && k == 2
xlswrite('Test.xls', [x y], 'Test1', 'p2');
end
if j == 2 && k == 1
xlswrite('Test.xls', [x y], 'Test1', 'b20');
end
if j == 2 && k == 2
xlswrite('Test.xls', [x y], 'Test1', 'p20');
end
end
end

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by