duplications for building array of integers or array of chars

조회 수: 1 (최근 30일)
Mohamed Jamal
Mohamed Jamal 2020년 7월 15일
댓글: Mohamed Jamal 2020년 7월 15일
Hi guys, I have a problem and it would be pleasure for your assistance.
I have array called y=[5 -1 6 7 9 0 7 3 -4 -4 6];
another array of integers called occurences[1 2 3 4 5 6 7 8 9 10 11]
what I want to implement in matlab is this to loop over array occurences and check at every i if y(i)>0 then I put value 1 in another array/string according to its replications occurences in array occurences at index i, and if y(i) is negative or zero then I put the value 0 according to its occurences in array occurences at index i, for example
y(i=1) >0 because 5>0 then I go to the same index i on the array occurences and check at the same index i=1 how many times should I put "1" in another array of integers or array of chars.
y(i=2) <0 because -1<0 then I go to the same index i on the array occurences and check at the same index i=2 how many times should I put "0" in another array of integers or array of chars.
the output is array of integers or array of chars that must look like [1 0 0 1 1 1 1 1 1 1 ...etc] , the outputs must be values of zero and ones that are accordingly concatenated to number of occurences at index i .
the output is an array could be integers like [1 0 0 1 1 1 1 1 1 1 ...etc] or array of chars like: '1001111111 .....' (doesn't matter which one!)
thanks alot
thanks alot !
  댓글 수: 1
madhan ravi
madhan ravi 2020년 7월 15일
편집: madhan ravi 2020년 7월 15일
What did you try for your homework? You need to first know the difference between string and character array first.

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

답변 (1개)

madhan ravi
madhan ravi 2020년 7월 15일
  댓글 수: 14
Mohamed Jamal
Mohamed Jamal 2020년 7월 15일
Hi! first I appreciate your effort, and really appreciated!
in your example code, could you tell me where is your occurance array? once again occurance arrray could be like this occurance=[100 10 1 2 1 90] not exactly [1 2 3 4 5 6 7 8 .. ]
thank for your assistance, my problem is that where is the occurence (replication) array in your code? thanks alot!
Mohamed Jamal
Mohamed Jamal 2020년 7월 15일
could you please explain those matlab code lines:
ix = 1:numel(y);
y1 = +(y >= 1);
Output = repelem(y1, ix)
what does ix=1:numel(y) gives me array or what? it sounds that every time ix takes a number from range 1:numberl(y) and then assign it to ix no? and what does +(y>=1) mean? exaclty the syntaxt + what it does to my condition y>=1? thanks alot
Yes I'm still not totally mastered in matlab, still need to master and learn more the matlab syntax!
appreciated for your explanation!

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by