zeros of a matrix
2 次查看(过去 30 天)
显示 更早的评论
I have a matrix and i want to create a column of zeros the size of the matrix.
M=rand(5)
A=zeros(size(M,2))
the error i get is
Index exceeds the number of array elements. Index must not exceed 2.
0 个评论
回答(2 个)
Walter Roberson
2022-12-1
You have accidentally created a variable with the name rand or the name size or the name zeros
Also, to create a column of zeros you should be using
A = zeros(1, size(M,2));
0 个评论
the cyclist
2022-12-1
The code you have posted here runs without error.
M=rand(5);
A=zeros(size(M,2));
My best guess here is that you have a variable in your workspace that has the same name as one of these functions: rand, zeros, or size.
I suggest you clear your workspace, rename any variables that have the same name as a MATLAB function, and try again.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!