error in if else

6 visualizaciones (últimos 30 días)
Rajat Ahuja
Rajat Ahuja el 26 de Feb. de 2018
Respondida: Jos (10584) el 26 de Feb. de 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

Respuestas (1)

Jos (10584)
Jos (10584) el 26 de Feb. de 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
...

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by