duplications for building array of integers or array of chars

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 Comment

What did you try for your homework? You need to first know the difference between string and character array first.

Sign in to comment.

Answers (1)

y >= 1

14 Comments

what? but what I tried doesn't work, if it works I wouldn't post my question :) and actually I dont know what do you mean y>=1
Your question is not clear. Stop adding answers just to make a comment. What would the output be for the below ?
y = [-3, 0 , 0 ,1] % ?
sorry about not making it clarify.
my question is that I want to build an array of integers or array of chars that has values 0 and 1 accordingly to number of replications that array occurence has at index i and related to value of array y at index i.
for instance at index i=1, the value y(1) >0 then I put value number 1 at the output array , but how many times should I put number 1? so here I check the occurences array at the same index i=1, and I put the value 1 in the output array according to its replications value on occurances array, in my case occurances(1)=1, so I put on the output array value 1 and just once because its occurance value at index 1 is 1! so I add value 1 at index i=1 on the output array that Im building.
assume the occurance at i=1 is 5, then I put/add on the output array five times the value 1 because y(1)>0 so I should add value 1 to my output array, but the question how many times? I check occurance(i=1) =5 then adding 5 times the value 1 to my array accordingly ..
the output for your example is related to occurence array , lets assume it's occurence=[1 2 3 4] then
at i=1, y(1) it's -3 <0 then I add to my output array value 1 , how many times? I check on the same index at array occurance(i=1) = 1, then I add one times because occurance(i=1)=1 .
etc ..
output should be in your case and according to my occurance array : [0 0 0 0 0 0 1 1 1 1 ] , or could be chars of array like '0000001111'
ix = 1:numel(y);
y1 = +(y >= 1);
Output = repelem(y1, ix)
once again you're still missunderstanding me, I have two arrays one is y values, the other is called occurences values that each value in it is represent how many time I add number 1 or zero (determenation of zero /one is determined by value of y) to output array.
the number of times I add 1 or zero to array output is related to array occurences at index i!
in your code here you're not relating to array occurences!
what's ix? is it implicitly the value of the array of occurences?
Your are still not understanding my question, replem is repeating all the values but I dont need this!
I want to repeat the value at specific index i according to array of occurence at index i
I want to repeat my current value according to y(i) by occurence(i) times ! but what you're attaching is something totally different!! I dont want to repeat whole the array values ! it depends on occurence at index i and according to that value of occurence(i) I repeat the value 1 or zero on the output array but not repeating whole the output value array!! just the current 1 or zero , this means the output array at the end would be for instance [1110000000000000001111110000000000000000]
I really dont know what is hard, I simplify once again
I have array called y=[1 2 -1 3] , also have another array called occurences=[1 2 3 4] that's represent the number of times that I add to output array . decision if it's 1 or zero is by this: if y(i)>0 then I add the value 1 , y(i) <= 0 I add value zero.
here my output is: [ 1 1 1 0 0 0 1 1 1 1 ] or array of chars '1110001111' , how many times I repeat 1 or zero is related on the occurence (i) value at the same index I check y(i) in order to decide if it's zero or one!
hope now more clear
>> y=[1 2 -1 3]
ix = 1:numel(y);
y1 = +(y >= 1);
Output = repelem(y1, ix)
y =
Columns 1 through 3
1 2 -1
Column 4
3
Output =
Columns 1 through 3
1 1 1
Columns 4 through 6
0 0 0
Columns 7 through 9
1 1 1
Column 10
1
I haven’t seen anyone so stubborn, jeez! You really need to do MATLAB On-ramp course , seem to be really struggling in the basics of MATLAB. By the way you talk as if you are the only one who knows everything , PLEASE STOP IT! Your comments feel like you’re commanding that others should do something that once you state something, that’s not how the real world works my friend! In one of your previous question , you’re in fact arguing about something that you don’t know. You asked the output to be a character array and infact it was a character array but you were arguing about it, I mean you can ask if you don’t know but you speak like as if others are the ones who know nothing.
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!
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!

Sign in to comment.

Tags

Asked:

on 15 Jul 2020

Commented:

on 15 Jul 2020

Community Treasure Hunt

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

Start Hunting!