Loop problem

Hello, I have a loop problem in Matlab
Consider the following datasets:
models = 5x10 (5 rows, 10 columns)
bsdata = 5x20 (5 rows, 20 columns)
I want to do the following calculation:
Result=models(bsdata);
If I do so, I obtain a 5x20 dataset. How can I do this for all the 10 columns of models? I would like to obtain a 10x200 dataset? I have tried the following, but it doesn’t work:
for i=1:10
Result=models(:,i)(bsdata);
end
Thanks,
Pieter

6 comentarios

Fangjun Jiang
Fangjun Jiang el 30 de Mayo de 2011
what do you mean by Result=models(bsdata) since models and bsdata are matrix. What operation do you want to do to obtain the results?
Charles
Charles el 30 de Mayo de 2011
Hi,
your question is confusing and maybe you should frame it better.
models = ones(5, 10); %gives a 5 x 10 matrix
bsdata =zeros(5, 20): % 5 x 20 matrix
Result=models(bsdata); %Are not possible, bsdata is larger than models
Result=bsdata(models);%Possible. References bsdata indexed by models.
for i=1:10
Result=models(:,i)(bsdata);
end
This part is not really clear. I think it is better you rather clarify what you mean with words.
Pieter
Pieter el 30 de Mayo de 2011
I try to explain it: bsdata is a dataset that picks random numbers from models. So if bsdata has the number 3, this means that it takes the third element from models. So if I do Results=models(bsdata), results will take the third number from models.
A short example:
models = [3;8;7;6]
bsdata = [2;2;1;4, 3;4;2;1]
If you do: result=models(bsdata);
result = [8;8;3;6, 7;6;8;3]
I hope this makes it more clear.
The problem I have is that he only does this calculation for the first column of models, and not for column 2-10.
Pieter
Pieter el 30 de Mayo de 2011
@ Charles, you are right, my example is not correct. Instead of models being a 5x10 matrix, make it a 5x30 matrix, than it should work (I think)
Oleg Komarov
Oleg Komarov el 30 de Mayo de 2011
Still not clear why you have a matrix for bsdata instead of a vector. How are you gonna draw a 5 by 20 matrix from a 5 by 30?
Pieter
Pieter el 30 de Mayo de 2011
You are right, it are vectors. I was using the wrong word.

Iniciar sesión para comentar.

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 30 de Mayo de 2011

0 votos

Then:
Result = models(bsdata,:);
You will draw rows direclty fro models.

Más respuestas (0)

Categorías

Más información sobre Measurement-Level Simulations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by