- #1
curious_iza
- 6
- 0
matlab matrix selection of data using for loops and if statements,,,,,
Hi people I was wondering if someone could assist me with the following;
You received the following data values from a coworker:
data = [-1.2, 3.3, 5.1, 0.2, 2.9, -0.1];
It turns out that the sensor used to collect the data is prone to noise and the real data should only contain positive even numbers. Write an M-File that rounds the positive values in data to the nearest EVEN integer. For example, 2.5 should be rounded to 2 and 3.1 will be rounded to 4. Negative numbers should be set to 0. HINT: You may want to use if statements and for loops
I can't do this question ... I have having issues with programming and am willing to put in the work to get really good.
My overall pattern of thinking was;
1) Fist of all I know that I want to select the positive answers and I will have to work with either mod/rem to get my remainders. Since I will have to differ between neg & positive I choose rem.
x = rem(data,2) % finds the positive and negetive remainder of the data matrix.
IN THE COMMAND WINDOW THIS GAVE:
x =
-1.2000 1.3000 1.2000 0.2000 0.9000 -0.1000
2) Ok ... so I need to get rid of the negs...
but if I go x > 0 then I will just get
0 1 1 1 1 0
and the values of my remainder are gone
I am really lost with this questions and it is meant to be 'easy' ... sigh ... I have played around for almost 3 HOURS and cannot get it... Please help me...
Thankyou
Hi people I was wondering if someone could assist me with the following;
You received the following data values from a coworker:
data = [-1.2, 3.3, 5.1, 0.2, 2.9, -0.1];
It turns out that the sensor used to collect the data is prone to noise and the real data should only contain positive even numbers. Write an M-File that rounds the positive values in data to the nearest EVEN integer. For example, 2.5 should be rounded to 2 and 3.1 will be rounded to 4. Negative numbers should be set to 0. HINT: You may want to use if statements and for loops
I can't do this question ... I have having issues with programming and am willing to put in the work to get really good.
My overall pattern of thinking was;
1) Fist of all I know that I want to select the positive answers and I will have to work with either mod/rem to get my remainders. Since I will have to differ between neg & positive I choose rem.
x = rem(data,2) % finds the positive and negetive remainder of the data matrix.
IN THE COMMAND WINDOW THIS GAVE:
x =
-1.2000 1.3000 1.2000 0.2000 0.9000 -0.1000
2) Ok ... so I need to get rid of the negs...
but if I go x > 0 then I will just get
0 1 1 1 1 0
and the values of my remainder are gone
I am really lost with this questions and it is meant to be 'easy' ... sigh ... I have played around for almost 3 HOURS and cannot get it... Please help me...
Thankyou