How can I get statements within functions to execute in a randomly chosen order? - matlab

I'm relatively new to Matlab, and I've been trying to solve my problem for ages but I'm just continuously arriving at a dead end.
I have a code which should, in theory, play 3 sounds in a random order (each order being different for each trial). Upon each sound playing the participant will be asked which sound they heard and then given feedback. I have all the code complete and working up until the random order part. I have created code that on each trial will randomly order 1,2 and 3.
Order = [1, 2, 3];
PhonemeOrder = randperm (numel(Order));
I then have a function which plays the sound/asks the questions etc. within this I have attempted switch cases statements and if else statements depending on the number that PhonemeOrder produces but the order doesnt change even when phoneme order does. I believe my problem is however that PhonemeOrder comes out like [1,2,3] or [3,1,2] which is what i wanted. but Im not sure how to get my sounds to play in the order that it shows because I am using code like...
if/ PhonemeOrder = 1;
then do this...
elseif phonemeorder = 2;
then do this...
else
do this...
Or I've tried code like
switch cases
case 1
do this
case 2
do this
case 3
do this
I'm guessing this is where i am going wrong, but i just dont know how to change it and make it work! I hope this makes sense? I just need it to play in the order that phonemeorder specifies, with the order changing on each trial.
Any help will be greatly appreciated :D

bexG,
I think you are on the right track.
The only thing you need is to use a "for-loop" to go through the array of PhonemeOrder.
for i=1:length(PhonemeOrder)
switch PhonemeOrder(i)
case 1
play the first song
case 2
play the second song
case 3
play the thrid song
end
end
I hope this will help.
Please let me know if you have any further question.

Related

how to write a text and calculation in a same time like Calcnote app in Flutter

I try lots of things but I failed kindly help me with how to do this and please someone shares a complete. I also share a screenshot of the original app I making same like this app.
App description:
1:When typing or calculating on the app if the user needs the next line and show a list num
2: The most important thing is when we calculate any num can we write something in the same type ( you think it's a notepad + calculator)?
3: Also when we write and type 5 + 5 we don't need to press = equal to. they abstract and subtract automatically.
thank you so much for your support.

Roblox Studio- Infinite yield possible

I am trying to code a FPS Game but when I tap the button to pick a gun it does not give it to me but instead says Infinite yield possible, anyways this is my code:
game.ReplicatedStorage.RemoteEvents.AKEvent.OnServerEvent:Connect(function(player)
local ak = game.ReplicatedStorage.Weapons.AK:Clone()
ak.Parent = player:WaitForChild("BackPack")
end)
In very little time I have already found what happened, so if it happens to you:
Backpack had a capital P and it was meant to be with a lower case P lol!

using the same function but on different rows

I want to estimate the co(variance) matrix of two assets classes (with different derivatives) of every month.. So let's assume that each month is 25 days. I will get the following code,
covar=cov([elec(1:25,:) ngas(1:25,:)])
However, I have like 5 years of data so rewrite everything seems like a waste of time, and I think there has to be an easier way to fix this problem.
ps. I do think the answer to my question is already answered somewhere, but I do not know the words the search on. Thanks for your reply
Sounds like you just need a for loop?
counter = 0;
cover{floor(size(elec,1)/25)} = []; %//Pre-allocation
for day = 1:25:size(elec,1)
counter = counter + 1;
covar{counter}=cov([elec(day:day+25-1,:) ngas(day:day+25-1,:)])
end

Editing Timeline from CCB file in cocos

I did some research into this and couldn't really find anything, so if this is a repetitive question I apologize. but anyway I have made a CCB file in CocosBuilder and I would like to start the timeline, for example, at one second instead of playing from the beginning. Is there a way to do this? Thanks for the help guys.
Edit: i would like this to be done in the code.
I am using 2.2.1 Cocos2DX version. I think there is no option to play it from given interval. But you can tweak yourself to get it done. (Not simple one)
You have to go to CCBAnimationManager and there you get "mNodeSequences".
It is dictionary and you get difference properties there like "rotation position etc..."
values there.
Internally AnimationManager reads this value (These values are specified in your CCB)
and puts in runAction queue.
So you have to break it as you want.(Ex. 5 min timeline you have. But you want to start
from 1 min then you have run first 1 min Actions without delay and for remaining you
have properly calculate tween intervals.
It's long procedure and needs calculation. If you don't know any other simpler way try this. If you know pls let us know (Post it).

Facebook Koala loop not working properly

The following is the code that does not work -
for x in #y
v = #graph.get_object("me") # This is not a useful code. I'm just trying to make a point
end
While the following code works
u = #graph.get_object("me")
for x in #y
v = u
end
I'd appreciate help with this issue. Thanks!
I tried testing something similar to this in the console, and saying something like
for i in 1..1000
#graph.get_object("me")
end
and after some amount of time, it finally finished.. but it took a while. I'm assuming there's a chance the connection between you and facebook can get blocked/closed/timeout.
Every call took about a second. I think the problem is that facebook's API has a bandwidth limit. So, in the case of your first block of code, you're calling get_object over and over, where as in the second one, you are simply calling the API once, then just assigning that value over and over.