Azzera filtri
Azzera filtri

write for loop output as matrix

2 visualizzazioni (ultimi 30 giorni)
Safwana Razak
Safwana Razak il 6 Gen 2021
Commentato: Safwana Razak il 6 Gen 2021
hi all,
can you advise me how to write my for loop output as matrix as below:
board 1 = 3x4matrix
board 2 = 3x4martix
for boardIdx = 1:params.NumPatterns %board number
R = params.RotationMatrices(:, :, boardIdx)';
t = params.TranslationVectors(boardIdx, :)';
worldBoardCoords = bsxfun(@plus, R * wpConvHull, t); %3x5 matrix
worldBoardCoords = worldBoardCoords(:,1:4) %3x4 matrix
end
  2 Commenti
KALYAN ACHARJYA
KALYAN ACHARJYA il 6 Gen 2021
output=zeros(3,4)
for i=1:3
for j=1:4
output(i,j)=........% Evaluate output
end
end
In most cases, you can avoid the loop (If not necessity), note on it.
Safwana Razak
Safwana Razak il 6 Gen 2021
hi Kalyan, thanks for your reply. is it possible to use bsxfun(@plus, a, t) where:
a = 3x5x9 and t = 3x9? i need to add a(:,:,1) + t(:,1), a(:,:,2) + t(:,2) and so on.
i tried it but it give me error "Error using bsxfun Non-singleton dimensions of the two input arrays must match each other."
sorry this is out of the scope of main question

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by