how can i convert an integer to an array in this function?

조회 수: 12 (최근 30일)
Zaza
Zaza 2013년 3월 31일
function a=get_array_num(n)
end
requirments:
1.no loops,if,recurion or logical operatos
2.no num2str or str2num
3.length_of(n)=number of digits in "n" (help function)
i think maybe logspace is useful here...but how?
  댓글 수: 8
Zaza
Zaza 2013년 4월 1일
sorry again
suppose n>0 with no leading zeros
Jan
Jan 2013년 4월 2일
For length_of() the log10 function would be much smarter.

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

답변 (1개)

Image Analyst
Image Analyst 2013년 3월 31일
How about
a = zeros(n);
or
a = n * ones(1, 10);
or something similar? There is an infinite variety of arrays you could make that would full those requirements, though requirement #3 is not well explained at all (no idea what it even means).
  댓글 수: 16
Zaza
Zaza 2013년 4월 2일
may i have a clue how to do it with the colon operator?
Jan
Jan 2013년 4월 2일
@Zaza: It consumed some time and energy to bring you to post an explicit example. We get some parts of the problem distributed to the question and over several comments. Therefore an efficient answer is impossible.
Please edit the original question and insert all available information. Then show us, what you have tried so far, because of course we are not going to solve your homework: you couldn't submit it anymore without cheating!

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by