How to increment a for loop through list elements in a vector, output a matrix of the same dimensions?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2014-9-10
编辑:Stephen23
2014-9-10
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Communications Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!