Why do I have a Syntax Error?

조회 수: 5 (최근 30일)
Tomasz Mlynowski
Tomasz Mlynowski 2012년 7월 19일
Why is this incorrect? how do I correct this?
BuyMatrix=(k,idx(i)) (k,p(idx(i)));
Error: File: pairstrading.m Line: 204 Column: 34 Expression or statement is incorrect--possibly unbalanced (, {, or [.
all variables are correctly specified as far as i know
just a problem with syntax and brackets
thanks
  댓글 수: 2
Jan
Jan 2012년 7월 19일
This is obviously no valid Matlab syntax. As long, as you do not explain, what you wnat to achieve, it is impossible to guess ameaningful suggestion for improvement. So please clarify, what this command should do.
Tomasz Mlynowski
Tomasz Mlynowski 2012년 7월 21일
What i want to achieve is to have a complete matrix of a for loop to be filled in reading from a [-1 1] vector. i have successfully done this for the first loop however it is not reading correctly the anyPos line
anyPos is to fill the matrix out for k.
for instance i have for i=1:length(idx)
if (k==1)||(anyPos(k-1,idx(i))==0)
if (dist(k,idx(i))>0)
assetsNumber=[idx(i) p(idx(i))];
directionTrade(k,assetsNumber) =[-1 1];
and i want create the correct anyPos to take the correct [-1 1] for idx(i) and p(idx(i))
i want to have
anyPosShort(k,idx(i))=-1;
anyPosLong(k,p(idx(i)))=1;
combined into one line
how do I do this?

댓글을 달려면 로그인하십시오.

채택된 답변

Kevin Claytor
Kevin Claytor 2012년 7월 19일
What are you trying to do; access a portion of BuyMatrix, or set BuyMatrix to be a matrix? The former would be accomplished with;
BuyMatrix(k,idx(i)) = ...;
The later would be done with;
BuyMatrix = <actual matrix expression>;
Matlab doesn't really know what to do with an expression of the type;
(1,2)
Just type that in and you'll get the same error. This isn't a vector ([1,2]), and it's not telling us to access row 1, col 2 of a matrix, nor does it correspond to any other command, hence the error.
  댓글 수: 1
Tomasz Mlynowski
Tomasz Mlynowski 2012년 7월 21일
What i want to achieve is to have a complete matrix of a for loop to be filled in reading from a [-1 1] vector. i have successfully done this for the first loop however it is not reading correctly the anyPos line
anyPos is to fill the matrix out for k.
for instance i have for i=1:length(idx)
if (k==1)||(anyPos(k-1,idx(i))==0)
if (dist(k,idx(i))>0)
assetsNumber=[idx(i) p(idx(i))];
directionTrade(k,assetsNumber) =[-1 1];
and i want create the correct anyPos to take the correct [-1 1] for idx(i) and p(idx(i))
i want to have
anyPosShort(k,idx(i))=-1;
anyPosLong(k,p(idx(i)))=1;
combined into one line
how do I do this?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 19일
Maybe you want
BuyMatrix = [k, idx(i); k, p(idx(i))];

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by