Loop for words vector

조회 수: 2 (최근 30일)
Dmytro
Dmytro 2014년 5월 30일
댓글: Yusef Ghazwan 2020년 6월 16일
Hallo everyone. I have a question. Is it possible to use a loop to create vector of words depending on the number.
As input I have a number, which can be changed according to any wish. And as a result i wont to get a row of words %input Number=10
C = cell(1,Number)
for i=1:Number
C(1,i)={'portfolio' *i* };
end
And using the loop I want a change of index "i"
Asa result Output have to be something like that: C={'portfolio 1','portfolio 2','portfolio 3','portfolio 4',......'portfolio 10'};
Hope to hear from you soon. Thanks in advance!
  댓글 수: 1
Yusef Ghazwan
Yusef Ghazwan 2020년 6월 16일
Show the output!

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 5월 30일
You can use the sprintf command to do what you require. Just modify your body of the for loop from what you have to
C{i} = sprintf('portfolio %d',i);
Note that since your code has defined C to be a cell array, the curly braces {} are used to access elements within it.
  댓글 수: 1
Dmytro
Dmytro 2014년 5월 30일
It is alive!!!! Thank you a lot!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by