I want to create an array, say n-by-100*n. I want the first column to be 1,2,...n, and the last column to be 2*pi,2*2*pi,...,n*2*pi, with linear spacing horizontally, similarly to the linspace function. What is the best way to do this? It tried something along the lines of:
arrayName = zeros(n, 100*n);
for k = 1:n
arrayName(k,:) = linspace(0,k*2*pi,100*k);
end
and it didn't work. Any suggestions?

 채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 12월 5일
편집: Mohammad Abouali 2014년 12월 5일

0 개 추천

arrayName=bsxfun(@times,(1:n)',linspace(1,2*pi,100*n))

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 5일
편집: Azzi Abdelmalek 2014년 12월 5일

1 개 추천

Your code is correct, you've just mistaken in the line [arrayName(k,:) = linspace(0,k*2*pi, 100*k )], you should write 100*n instead of 100*k
arrayName = zeros(n, 100*n);
for k = 1:n
arrayName(k,:) = linspace(0,k*2*pi,100*n);
end

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2014년 12월 5일

편집:

2014년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by