How to increment a for loop through list elements in a vector, output a matrix of the same dimensions?
1 view (last 30 days)
Show older comments
Callan Turley
on 10 Sep 2014
Commented: Callan Turley
on 18 Sep 2014
I have a vector s = [a b c d], each of the elements in the vector are 7 by 1 lists of 1's and 0's.
I need to make a for loop that will use the randerr function to flip 1 bit in each list. This is what I have so far:
for i = 1:length(s);
t = randerr(1,7);
reshape(t,7,1);
u = abs(s(:,i)-t);
end
But Matlab tells me the matrix dimensions do not agree..
I am obviously doing something wrong when trying to apply -t to each of the elements of s, but I've been searching through these forums and google for a while now and I can't find anything helpful.
Any help would be greatly appreciated.
0 Comments
Accepted Answer
Stephen23
on 10 Sep 2014
Edited: Stephen23
on 10 Sep 2014
MATLAB does not have a data type "list". I presume you are talking about numeric data, ie a numeric array. What is referred to in some programming languages as a "list" is called a cell array in MATLAB.
You are subtracting t (size 1x7) from s(:,i) (size 7x1). These dimensions do not match, as the error message clearly states. Did you check the dimensions using the size command?
Presumably you intended that reshape command to change the shape of t , but without allocating its output to a variable, it does nothing whatsoever in this code. Instead of using reshape , why not just use randerr to create t with the correct size?
More Answers (0)
See Also
Categories
Find more on Communications Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!