For loop for a comparing values of a column vector with a value
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mike Mierlo van
il 17 Dic 2019
Commentato: Cappriece Clarke
il 5 Lug 2021
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
0 Commenti
Risposta accettata
Ridwan Alam
il 17 Dic 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 Commenti
Cappriece Clarke
il 5 Lug 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".
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!