loops

3 visualizaciones (últimos 30 días)
Pieter
Pieter el 12 de Abr. de 2011
Hello,
I have the following problem in Matlab: Consider dataset a, with the following two columns:
0 / 0
0 / 0
1 / 0
1 / 0
1 / 9
0 / 0
-1 / 0
-1 / 4
0 / 0
My problem is that the value 9 has to be spread equally during the time that column 1 is equal to 1. The same has to be done with the value 4 during the time that column 1 is equal to -1. The result I have to obtain is the following:
0 / 0
0 / 0
1 / 3
1 / 3
1 / 3
0 / 0
-1 / 2
-1 / 2
0 / 0
Thanks,
Pieter
  1 comentario
Oleg Komarov
Oleg Komarov el 12 de Abr. de 2011
What have you done so far?

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 12 de Abr. de 2011
Guessing this is homework, but not sure, so I will give you a solid kick in the right direction. Here is part of what you need to do, with a lot of assumptions about things you were not specific about.
A = [0 0; 0 0; 1 0; 1 0; 1 9; 0 0; -1 0; -1 4; 0 0];
indexToOnes = (A(:,1)==1);
numberOfOnes = sum(indexToOnes);
valueToDistribute = max(A(indexToOnes,2));
A(indexToOnes,2) = valueToDistribute/numberOfOnes
It does not handle the -1 part, which maybe you can figure out for yourself.

Más respuestas (1)

Oleg Komarov
Oleg Komarov el 12 de Abr. de 2011
A = [0 0
0 0
1 0
1 0
1 9
0 0
-1 0
-1 4
0 0];
A(3:5,2) = 3;
A(7:8,2) = 2;

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by