On Wed, Jun 24, 2020 at 11:09 AM Ganesh Kini <
ganeshrkini19@gmail.com> wrote:
>
> Rather than hardcore it, like >> pos_a_1 = (condition1(:,2)=='a')
> how can i make it in general? Do I need to use for loop? Please let me know how to do it ?
>>>
>>>
what do you mean 'in general'? you mean for the 'a' part? 'a' is just a string. you can put any variable in there. do you mean where I saved that result in the pos_a_1 variable? I just did that for convenience. You can index the data directly without assigning the index array to a variable. e.g.,:
current_condition = 'a';
output = supply1_1(condition1(:,2)==current_condition) - supply1_2(condition2(:,2)==current_condition)
you could do it in a for loop. But only you know what you want to do with the data after you've done the subtraction, so I don't know how you want to build your output. but something like the following stores the info in a cell array (since the number of data points for ta, tb, tc are different):
ouput_position = 1;
for current_condition = ['a', 'b', 'c']
output{output_position} = supply1_1(condition1(:,2)==current_condition) - supply1_2(condition2(:,2)==current_condition) ;
output_position++;
endfor
>> output
output =
{
[1,1] =
-3.7400
1.3000
[1,2] =
-0.050000
-3.270000
-3.600000
[1,3] =
-3.03000
-0.93000
0.12000
}