How can prelocate arrays?
이전 댓글 표시
I have an array like A which I want to have all of its elements zero by using Matlab features like zeros(x) function.
for example:
A=[1*3][1*3][1*3][1*3]
Each 1*3 matrix in the array A should have 3 zero.
I know how to make matrices with zero elements e.g zeros(2,3) but I don't know how to use it for array shown above with Matlab features without using simple loops.
댓글 수: 3
We can't recognize what kind of array A is. Please execute
>> whos A
and show us the output.
Matt J
2013년 4월 23일
If A is a cell array, then my Answer below will be applicable.
채택된 답변
추가 답변 (1개)
This might be what you need
out = cellfun(@(c) zeros(size(c)), A, 'uni',0),
It has shorter syntax than a loop, but is not faster.
카테고리
도움말 센터 및 File Exchange에서 Elementary Math에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!