error in if else

6 visualizzazioni (ultimi 30 giorni)
Rajat Ahuja
Rajat Ahuja il 26 Feb 2018
Risposto: Jos (10584) il 26 Feb 2018
I have two files with 252 rows and 1 coloumn. I am trying to implement this for loop with if else condition but getting error(Error: File: v.m Line: 509 Column: 13 Unbalanced or unexpected parenthesis or bracket.). Can you please help? cbob and wti are the 2 csv files(attached) which I have imported using import data in Matlab.
if true
portfolio=zeros(253,1);
for i=1:252
if (cbob [i] > 72)
portfolio[i]= 72 ;
else portfolio[i]= CBOB[i] ;
else if(wti[i]>60)
portfolio[i]=wti[i];
else portfolio[i]=60;
end
end

Risposte (1)

Jos (10584)
Jos (10584) il 26 Feb 2018
In Matlab, indexing is done by round brackets, and concatenation by square brackets:
A = [1 2 3]
B = [A 4 5] % concatenation
B(4) % indexing
so
if cbob(i) > 72
...

Community Treasure Hunt

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

Start Hunting!

Translated by