calling for the same data based on a result

  • data1 = a
  • data2 = b
  • x = a*b;
  • c = a;
  • for i = 0
  • if c > 5
  • c = 1
  • else
  • c = 0
  • end
I want to write a code such that if c = 1 it will take data1. I am trying to write a code but I am getting a confused how to return to data1 if c = 1 is the result

6 Comments

Is there a more complete version of your code? I'm confused how c will ever be anything besides 'a'.
Also, what do you mean by 'take' data1. Do you want to set c equivalent to data1, or are you looking to display the value? Is there some other operation that you would like to complete with data1 as an input?
yes I am trying to use that value in some other operation
tag0 = 0;
sco = [1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0];
out0 = xor(tag0,sco);
tag1 = 1;
sc1 = [1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0];
out1 = xor(tag1,sc1);
tag2 = 1;
sc2 = [1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0];
out2 = xor(tag2,sc2);
volts0 = ((-5 + 10*(out0))*0.35);
volts1 = ((-5 + 10*(out1))*1.4);
volts2 = ((-5 + 10*(out2))*0.9);
voltsadd = volts0 + volts1 + volts2;
x = voltsadd;
x(x>=0) = 1;
x(x<=0) = 0;
x_0 = x;
x_1 = x;
x_2 = x;
despread_x0_usingsco = xor(x_0,sco);
despread_x1_usingsc1 = xor(x_1,sc1);
despread_x2_usingsc2 = xor(x_2,sc2);
tag0_data = despread_x0_usingsco;
tag1_data = despread_x1_usingsc1;
tag2_data = despread_x2_usingsc2;
count_tag0 = nnz(tag0_data == 1);
count_tag1 = nnz(tag1_data == 1);
count_tag2 = nnz(tag2_data == 1);
for i = 0
if count_tag0 > 8
then count_tag0 = 1
else
count_tag0 = 0;
end
end
for j = 0
if count_tag1 > 8
count_tag1 = 1;
else
count_tag1 = 0;
end
end
for l = 0
if count_tag2 > 8
count_tag2 = 1;
else
count_Tag2 = 0;
end
end
here I have to check the values of count_tag0, count_tag1 and count_tag2
if my count_tag0 is greater than 8 I am trying to write a code that will automatically select its sc1\sc2\sc0 in next operation
"then" is not a word used in MATLAB.
Also, the format for a for loop is to have a starting and stopping value - you have just a single value or i, j, or l equal to zero so the for loop only executes once.
yes i did remove then from the statement. isnt it okay if the for loop executes once? I am sorry I didn't understand your point?
I think it's possible for Matlab to execute a for loop only once, it's just redundant because you can just execute the commands once without the loop.
For your if statements your conditions seem to be set up right, I would just replace the count_tag0 = 1 type lines with the execution of your next operation with sc1/sc2/sc0 as an input. Defining count_tag to be 1 is a bit redundant.
if count_tag0 > 8;
result = operation(sc0);
end
if count_tag1 > 8;
result = operation(sc1);
end
if count_tag2 > 8;
result = operation(sc2);
end

Answers (0)

This question is closed.

Asked:

on 31 Oct 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!