"Subscripted assignment dimension mismatch" Please correct my program. tell me idea/logic to make sequence
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Triveni
el 22 de Feb. de 2016
Comentada: Stephen23
el 23 de Feb. de 2016
s = [30 30 30 30 30 30 0 0 0 0];
s = sort(s, 'descend'); %sorting sequence s
uniques = unique(s); % finding unique elements
for k = 1: length(uniques)
ua(:,:,k) = repmat(uniques(:,k),1 ,(length(s))); %repeating unique values for combine
end
for k= 2:length(s)
for j = length(s)-2:-1:1
for l = 1:6
ua1(:,:,1) = [ua(1, 1:j, 1), ua(1, 1:k, 2)]; %cut and combine values
end
end
end
output ua1
ua1 =
0 0 0 0 0 0 0 0 30 30
my loop for ua1 is not working. please help me.
I want to generate sequence
ua1(:,:,1) = [0 0 0 0 0 0 0 0 30 30];
ua1(:,:,2) = [0 0 0 0 0 0 0 30 30 30];
ua1(:,:,3) = [0 0 0 0 0 0 30 30 30 30];
ua1(:,:,4) = [0 0 0 0 0 30 30 30 30 30];
ua1(:,:,5) = [0 0 0 0 30 30 30 30 30 30];
ua1(:,:,6) = [0 0 0 30 30 30 30 30 30 30];
or if possible tell me trick to make
[0 0 0 0 0 0 0 0 0 30;
0 0 0 0 0 0 0 0 30 30;
0 0 0 0 0 0 0 30 30 30;
0 0 0 0 0 0 30 30 30 30;
0 0 0 0 0 30 30 30 30 30;
0 0 0 0 30 30 30 30 30 30;
0 0 0 30 30 30 30 30 30 30;
0 0 30 30 30 30 30 30 30 30;
0 30 30 30 30 30 30 30 30 30];
0 comentarios
Respuesta aceptada
Stephen23
el 22 de Feb. de 2016
Editada: Stephen23
el 22 de Feb. de 2016
Don't waste time with all of those loops when you can simply use hankel to generate the whole matrix:
>> hankel(zeros(1,9),[0,30*ones(1,9)])
ans =
0 0 0 0 0 0 0 0 0 30
0 0 0 0 0 0 0 0 30 30
0 0 0 0 0 0 0 30 30 30
0 0 0 0 0 0 30 30 30 30
0 0 0 0 0 30 30 30 30 30
0 0 0 0 30 30 30 30 30 30
0 0 0 30 30 30 30 30 30 30
0 0 30 30 30 30 30 30 30 30
0 30 30 30 30 30 30 30 30 30
6 comentarios
Más respuestas (1)
Walter Roberson
el 22 de Feb. de 2016
ua1(:,:,1) = [ua(1, 1:j, 1), ua(1, 1:k, 2)]; %cut and combine values
In that code, 1:j will have one length for the first j, but for the next j would have a different length. Therefore for different iterations of j, the right hand side will be different sizes, but each time you try to write it to the same size on the left.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!