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

MATLAB Help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 4

File: 1443042847868.png (454KB, 396x435px) Image search: [Google]
1443042847868.png
454KB, 396x435px
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 (74KB, 573x621px) Image search: [Google]
image.jpg
74KB, 573x621px
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 (3KB, 267x499px) Image search: [Google]
dumbos.png
3KB, 267x499px
>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 (47KB, 652x483px)
Matlab.jpg
47KB, 652x483px
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 posts: 22
Thread images: 4


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.