How to implement this algorithm?

I have a doubt in the above code. I want to declare x=x1,x2,x3..x8 But i got an error
clc;
clear all;
close all;
x=[0 1 1 0 1 1 0 1];
y=[0 0 0 0 0 0 0 0];
for j=1:8
x[j] = [xj:xj+1];
Yj = (xor(yj-1,xj)*H);
end
Y
The error was: Undefined function or variable 'xj'.
Error in counter1 (line 9) x=[xj:xj+1];
>> counter1 Error: File: counter1.m Line: 9 Column: 8 Unbalanced or unexpected parenthesis or bracket.

7 Commenti

John D'Errico
John D'Errico il 19 Set 2017
Modificato: John D'Errico il 19 Set 2017
You cannot create a variable as x[j], hoping to create numbered variables. Nor can you ever access the j'th such variable that you just created using xj.
Instead, learn to use cell arrays.
xcell{j} = [xj:xj+1];
You access it using xcell{j}.
I called it xcell, because you already created the variable x as a vector.
Really, what you need to do is to learn MATLAB. There are multiple errors in what you are doing, basic ones that suggest you will benefit from reading the getting started tutorials.
The variable xj is used before it is created. Did you mean x(j) and x(j+1) in line 9?
Can you please suggest good tutorials on bits. I am totally new to bitwise operation in matlab. I will surely learn about xcell{} operation. I would be glad if you could help me out with this problem.
I have attached the algorithm here. Suppose x=[0 1 1 0 1 1 0 1] y=[0 0 0 0 0 0 0 0] H=[1 1 0 0 0 0 0 0] In the algorithm i am checking for each bit, in vector x Thus step 3 of algorithm, Yj = (xor(yj-1,xj)*H); I actually want it for vectors Y1,Y2 and so on. What must I do?
Rik
Rik il 19 Ott 2017
You really shouldn't try to run before you can walk. Once you've finished a good tutorial, this will be almost trivial.
I have no personal experience with these, but there are several offered by Mathworks: https://matlabacademy.mathworks.com/
The MATLAB Onramp course (on the MATLAB Academy page) is free, and particularly suited for new users. I'd highly suggest that one.
Exactly. The problem here is not with how to do bitwise operations in MATLAB, but that you seem to not understand fundamental ideas in MATLAB, like how to index an array. Learn to use MATLAB first.
ok.Thanks

Accedi per commentare.

Risposte (0)

Categorie

Tag

Richiesto:

il 19 Set 2017

Commentato:

il 19 Ott 2017

Community Treasure Hunt

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

Start Hunting!

Translated by