Switching and repeating languages equally in an experiment
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear All,
I am trying to create an experiment in Matlab which is the following.
I have two languages L1 and L2 (lets say L1 is English and L2 is French).
The experiment is to show for instance a word in English afterwards another word in English after that a word in French after that again in English etc. So what is happening for a bilinguist the experiment should show how fast you can switch from one language to another.
Now I need to create a code in Matlab to count how many times I am switching or repeating the specific languages and at the end the number of repeating and switching from one language to another should be equal. E.g --> the first one should always be like a constant L1 L1r L2s L2r L1s L1r L2s L2r L1s. What you can see here is L1r=2times L1s=2times L2r=2times and L2s=2times. The way we are switching and repeating the languages should be equal. Now i need to create an algorithm for that in Matlab. If you have any ideas how i can proceed please let me know.
It might be super simple but i only need the initializer for this.
Thank you for your help in advance.
Looking forward to hearing from you.
0 comentarios
Respuestas (1)
Spruha
el 29 de En. de 2025 a las 10:47
Hello Amra,
From the question it seems that you want to count no. of switches and repeats that is happening in given sequence of words for given Language. There are 2 languages: L1 and L2 as stated in the query.
For implementing this, please refer to the following steps:
1. You can start by having 2 vectors, one for each Language that contains word from respective language.
L1_words = {'apple', 'banana', 'cherry'};
L2_words = {'pomme', 'banane', 'cerise'};
Then initialize counter for switch and repeat for each language.
L1_repeat_count = 0;
L1_switch_count = 0;
L2_repeat_count = 0;
L2_switch_count = 0;
2.You can define functions to find which language the word belongs.
% Function to determine language
is_L1 = @(word) ismember(word, L1_words);
is_L2 = @(word) ismember(word, L2_words);
Define a variable which indicate the previous language used. This will help to identify switches or repeats.
Prev_lan="";
3. Use FOR loop to iterate through the given sequence to count no. of switches and repeats. Refer to the pseudo code below
For each word in the sequence:
If is_L1(word):
If Prev_lan is 'L1':
Increment L1_repeat_count
Else if Prev_lan is 'L2':
Increment L1_switch_count
Set Prev_lan = 'L1'
Else if is_L2(word):
If Prev_lan is 'L2':
Increment L2_repeat_count
Else if Prev_lan is 'L1':
Increment L2_switch_count
Set Prev_lan = 'L2'
By comparing the counter for switch and repeat you can check if they are equal or not.
For more details about ‘ismember’ function, refer to this documentation: https://www.mathworks.com/help/matlab/ref/double.ismember.html
For more information about FOR loop, refer to this documentation: https://www.mathworks.com/help/matlab/ref/for.html
Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!