Multiplication of vectors in for loops
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I am wondering how to make this for loop work. Each radius value results in a vector product containing 3 numbers. I wanted those three numbers to occupy each row ( so that each row is a new vector from each radius multiplication ).
radius = [3,3] % contains 9 different values
Tdims= zeros(9,3)
for i = 1: length(radius)
for j= radius
Tdims(j,i)= sin (anglesRad) .* radius (j) + ycenter - 100 % each vector product is its own row
end
end
0 comentarios
Respuesta aceptada
Voss
el 15 de Feb. de 2023
Possibly this:
radius = rand(3,3); % contains 9 different values
ycenter = 0;
anglesRad = [0 1 2]; % I guess this is a 1-by-3 vector based on your description
nr = numel(radius);
na = numel(anglesRad);
Tdims = zeros(nr,na);
for i = 1:nr
Tdims(i,:) = sin(anglesRad) .* radius(i) + ycenter - 100; % each vector product is its own row
end
disp(Tdims);
2 comentarios
Más respuestas (1)
Sulaymon Eshkabilov
el 15 de Feb. de 2023
Editada: Sulaymon Eshkabilov
el 15 de Feb. de 2023
If understood your question correctly, this is how you can get it done:
radius = randi(10, 3, 3); % contains 9 different values
ycenter = 1;
anglesRad = deg2rad([30, 60 90]);
Tdims= zeros(size(radius));
for ii = 1:size(radius,1)
for jj= 1:size(radius,2)
Tdims(ii,jj)= sin(anglesRad(ii))* radius (ii,jj) + ycenter - 100; % each vector product is its own row
end
end
Tdims
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!