greater than less than

6 次查看(过去 30 天)
Ayesha Punjabi
Ayesha Punjabi 2019-2-15
  1. close all;
  2. tag_arr = randi(0:1,1,8);
  3. N = 16;
  4. hadamardmat = hadamard(N);
  5. codeTx1 = hadamardmat(:,1);
  6. codeTx2 = hadamardmat(:,2);
  7. codeTx3 = hadamardmat(:,3);
  8. codeTx4 = hadamardmat(:,4);
  9. codeTx5 = hadamardmat(:,5);
  10. codeTx6 = hadamardmat(:,6);
  11. codeTx7 = hadamardmat(:,7);
  12. codeTx8 = hadamardmat(:,8);
  13. code_Tx9 = hadamardmat(:,9);
  14. code_Tx10 = hadamardmat(:,10);
  15. code_Tx11 = hadamardmat(:,11);
  16. code_Tx12 = hadamardmat(:,12);
  17. code_Tx13 = hadamardmat(:,13);
  18. code_Tx14 = hadamardmat(:,14);
  19. code_Tx15 = hadamardmat(:,15);
  20. code_Tx16 = hadamardmat(:,16);
  21. scm = [codeTx1 codeTx2 codeTx3 codeTx4 codeTx5 codeTx6 codeTx7 codeTx8 code_Tx9 code_Tx10 code_Tx11 code_Tx12 code_Tx13 code_Tx14 code_Tx15 code_Tx16];
  22. sc_t = scm;
  23. sc_t(sc_t == -1) = 0;
  24. sc_o=sc_t;
  25. no_oftags = 5;
  26. out_array = zeros(no_oftags,16);
  27. for n = 1:no_oftags
  28. out_array(n,:) = xor(tag_arr(1,n),sc_t(n,:));
  29. end
  30. tau = zeros(1,no_oftags);
  31. sigma = 1;
  32. for n = 1:no_oftags
  33. tau(1,n) = sigma*sqrt(-2*log(1-rand(1)));
  34. end
  35. volts_forall = zeros(no_oftags,16);
  36. for n = 1:no_oftags
  37. volts_forall(n,:) = ((-5 + 10*(out_array(n,:)*tau(1,n))));
  38. end
  39. volts_add = zeros(1,16);
  40. for n = 1:no_oftags
  41. volts_add(1,:) = volts_add + (volts_forall(n,:));
  42. end
  43. voltsadd_val = volts_add;
  44. voltsadd_val(voltsadd_val>=0) = 1;
  45. voltsadd_val(voltsadd_val<0) = 0;
I am trying a code where I have to simple make all the positive values to 1 and negative values to 0 in voltsadd_val matrix but whenever i run the program the syntax doesnt work prroperly. I dont know whats wrong ..
eg
volts_add =
Columns 1 through 11
10.2478 11.0875 8.3853 -11.0500 14.2229 15.0626 12.3604 -7.0749 10.2478 11.0875 8.3853
Columns 12 through 16
-11.0500 14.2229 15.0626 12.3604 -7.0749
voltsadd_val =
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

回答(2 个)

Kevin Phung
Kevin Phung 2019-2-15
here's an example:
voltsadd_val = [1 5 3; -2 -5 5; 1 -5 3];
voltsadd_val(voltsadd_val>0) = 1; % if pos, 1
voltsadd_val(voltsadd_val<0) = 0; % if neg, 0
  2 个评论
madhan ravi
madhan ravi 2019-2-16
Suspect the OP did the same thing not sure why the OP says it doesn’t work though. Maybe more expanation is needed then.
Ayesha Punjabi
Ayesha Punjabi 2019-2-18
matlab.JPG
I tried running the code with the syntax mentioned above but its just not showing the required results like in this case the last bit is negative but its showing as the output.
I tried with many ways but I am not sure y its showing such result

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2019-2-18
voltsadd_val = volts_add >= 0;
No logical indexing required.

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by