Borrar filtros
Borrar filtros

For loop for a comparing values of a column vector with a value

2 visualizaciones (últimos 30 días)
Hi, I want to perform the following, but I get unexpected outcome. The plan is:
1: make column vector ‘costs’
2: for every iteration of ‘i’ compare every value in vector ‘costs’ with the value of ‘PM_cyc’.
3: If the value of the element in ‘costs’ < PM_cyc, than that element changes in PM.
4: If the value of the element in ‘costs’ > PM_cyc, than that element changes in CM.
5: I expect an outcome for the code below as an matrix With size 10x20. 10 rows becose every iteration cost is a column vector of 10 elements. 20 columns because of 20 iterations. The values in this matrix are PM or CM. But I get an error instead. Please help.
Fail = [95:105];
CM = 9000; %euro
PM = 2000; %euro
costs=[Fail]';
PM_cyc = 90:110;
for i = 1:length(PM_cyc)
costs(costs>PM_cyc(i))=PM;
costs(costs<PM_cyc(i))=CM;
costs(i);
end

Respuesta aceptada

Ridwan Alam
Ridwan Alam el 17 de Dic. de 2019
costs=[Fail]';
costs = repelem(costs,1,length(PM_cyc));
output = zeros(size(costs));
for i = 1:length(PM_cyc)
output(find(costs(:,i)<=PM_cyc(i)),i)=PM;
output(find(costs(:,i)>PM_cyc(i)),i)=CM;
end
  4 comentarios
Cappriece Clarke
Cappriece Clarke el 5 de Jul. de 2021
Hi Ridwan Alam,
I would like to do something similar, by testing the maximum likelihood function and the wald test (separately) on each parameter in a column vector and having the results stored in a different array. Can you assist me with this please. Let's say the vector is called "colVect".

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by