A = [2 5 7 3
1 3 4 2];
[rows, cols] = size(A);
odds = 1:2:cols;
disp('odd columns of A using predefined indices')
A(:, odds)
disp('odd columns of A using anonymous indices')
A(end, 1:2:end)
disp('put evens into odd values in a new array')
B(:, odds) = A(:, 2:2:end)
disp('set the even values in B to 99')
B(1, 2:2:end) = 99
disp('find the small values in A')
small = A < 4
disp('add 10 to the small values')
A(small) = A(small) + 10
disp('this can be done in one ugly operation')
A(A < 4) = A(A < 4) + 10
small_index = find(small)
A(small_index) = A(small_index) + 100
为什么报错第9行 说左侧是34的右侧是14的 我看半天 左右两侧不都是1*4的吗 还有就是这串代码有什么功能
这里没看见对B进行定义,看不出来B的原始大小,建议用size检查一下B的真正的大小。
如果非要运行的的话,写B(1,odds)=A(1,2:2:end)就好了吧。