[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
MATLAB Help

You are currently reading a thread in /sci/ - Science & Math

Thread replies: 22
Thread images: 4
File: 1443042847868.png (454 KB, 396x435) Image search: [Google]
1443042847868.png
454 KB, 396x435
I cant seem to figure this out, and I always overthink stuff when it comes to programming and MATLAB, but any help would be amazing.

Two Gymnasts are competing with each other.


How do I write a program that uses find to determine how many events each gymnast won.

gym1=[9.821
9.923
9.624
9.432
9.534
9.203]

gym2=[9.700
9.925
9.83
9.987
9.354
9.879]
>>
>>7649011
I guess the vectors are something like the time they ran so the one with the lower number won? Just define to variables to denote the number of times each Gymnast won and the interate over the entries of the vectors and increase the variable of whoever has the lower entry.
Im not gonna write the code for you, because it´s your homework.
>>
File: image.jpg (74 KB, 573x621) Image search: [Google]
image.jpg
74 KB, 573x621
Lol MATLAB
>>
>>7649054
It is whoever has the highest score, I understand what you are saying, but how would I write that with the vectors? would i just be like vault1=find(gym1:1,gym2:2) ? I just dont understand how you write this piece.
>>
>>7649060
yeah fuck matlab, this shit isnt anything close to fun, plus the instructor is trash and the SI is about the same. Everything with this is so fucking vague all the time.
>>
>>7649064
The last time I had to write Matlab code was some time ago, so maybe theres an easier way to do this. As far as I remember you can just write something like
if (gym1(i)>gmy2(i))
x_1=x_1+1;
elseif (gym1(i)>gmy2(i))
x_2=x_2+1;
>>
>>7649076
I meant
elseif (gym1(i)<gmy2(i))
for the second condition of course.
>>
>>7649011
the number of positive numbers in gym1-gym2 is how many events gym1 won, the number of negative numbers is how many gym2 won

gym1_wins = sum(gym1 - gym2 > 0);
gym2_wins = sum(gym1 - gym2 < 0);
ties = sum(gym1 - gym2 == 0);
>>
File: dumbos.png (3 KB, 267x499) Image search: [Google]
dumbos.png
3 KB, 267x499
>not just using boolean comparisons
this is literally a 1loc question
>>
>>7649076
>>7649079
>>7649080
Okay now this makes sense! Thankyou I really appreciate this. This was driving me insane. I have spent an hour on this one problem.
>>
>>7649080
>>7649085
>>7649087
>>7649079
>>7649076
>>7646666
You just must compare the results each athlete has in each discipline and count the winner's winning counter one up.
This is so easy really

Sorry but your answers are litterally a waste of time
>>
>>7649096
our answers solve the problem OP specified.

if OP left out details, that's not our problem
>>
I know it is a waste of time, You guys explained everything amazingly. I was just overthinking this way too fucking hard like I always do with programming stuff. Thankyou again, I really appreciate it!
>>
>>7649080
>>7649085
Yeah i knew you could do it easier but i always forget that in matlab everything that has to do with matrices is pretty much "Yeah just write what you want, Matlab will get it"
>>
>>7649104
a good rule of thumb is that if you're using a for-loop in matlab you're doing something wrong
>>
m=numel(gym1)
win1=zeros(m);
n=1;

while n<=m

if gym1(n)<gym2(n)

win1(n)=1;

end

n=n+1;

end
>>
>>7649138
just no
>>
>>7649011
>that uses find

You don't need find and avoid it where it isn't needed.

sum(gym1<gmy2) % for gym1's wins
sum(gym1>gmy2) % for gym2's wins
sum(gym1==gmy2) % for ties

>>7649080
>subtraction then comparison

wtf are you doing?

>>7649138
>loops
>while instead of for n=1:m

>>>/g/tfo
>>
non related to matlab, c# algo

gym1.Select((value, i) => value - gym2[i]);

Values = 0, tie
Values > 0, gym1 wins
Values < 0, gym2 wins

easy intersecting index loop
>>
File: Matlab.jpg (47 KB, 652x483) Image search: [Google]
Matlab.jpg
47 KB, 652x483
NEVER USE LOOPS IN MATLAB UNLESS YOU REALLY HAVE TO.
>>
>>7650400
>find
>not just sum

fail
>>
>>7649282
>subtraction then comparison
>wtf are you doing?

Not that Anon, but what he's doing is similar to the comparto method in comparable interface and the compare method in comparator Interface.

His method is actually better because it builds a better fundamental understanding of comparing elements. Later on when comparing objects his method will work, and yours will not.
Thread replies: 22
Thread images: 4

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK