数组索引问题。

5 vues (au cours des 30 derniers jours)
sopdaer
sopdaer le 16 Mai 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的整数啊

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB 快速入门 dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!