How can i achieve this "linspace" problem?
조회 수: 10 (최근 30일)
이전 댓글 표시
I should create 3 matrix (named as "d") with using linspace, but i can not use linspace command in for loop as at the code box. What is the reason of this problem?
Thanks,
kk=[8 10 12]
for j=1:numel(kk)
d(j)=linspace(0,50,kk(j))
end
alternatively;
for r=1:1:numel(kk)
for u=1:1:numel(kk)
dd(r,:)=linspace(0,50,kk(u))
end
end
I want to create 3 dd matrixes with using linspace by 8,10 and 12 values.
댓글 수: 0
채택된 답변
Stephen23
2018년 5월 4일
편집: Stephen23
2018년 5월 4일
It is not possible to put multiple elements into one element of a numeric array. Use a cell array:
vec = [8,10,12];
d = cell(size(vec));
for k = 1:numel(vec)
d{k} = linspace(0,50,vec(k));
end
giving:
>> d{:}
ans =
0.00000 7.14286 14.28571 21.42857 28.57143 35.71429 42.85714 50.00000
ans =
0.00000 5.55556 11.11111 16.66667 22.22222 27.77778 33.33333 38.88889 44.44444 50.00000
ans =
0.00000 4.54545 9.09091 13.63636 18.18182 22.72727 27.27273 31.81818 36.36364 40.90909 45.45455 50.00000
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!