数组索引问题。

6 views (last 30 days)
sopdaer
sopdaer on 16 May 2023
Answered: pongens on 16 May 2023
clear all;
N = 20;
for i = 1 :N
A{i} = rand(5)
end
whos A
for j = 1:4
if j ==2|j== 4
B{j} = [A{5j};A{5j-1};A{5j-2};A{5j-3};A{5j-4}]
elseif j == 1|j ==3
B{j} = [A{5j-4};A{5j-3};A{5j-2};A{5j-1};A{5j}]
end
end
[size=13.3333px]出错 test (第 12 行) B{j} = [A{5j-4};A{5j-3};A{5j-2};A{5j-1};A{5j}]
[size=13.3333px]这里显示12行索引错了,但是我算了一下索引是大于0的整数啊

Accepted Answer

pongens
pongens on 16 May 2023
请养成好习惯,不要误以为现实中的数学式写法能在MATLAB中也通用。
新手常见错误就有把必要的乘号省略、把圆括号方括号花括号乱用。

More Answers (0)

Categories

Find more on MATLAB 快速入门 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!