Creating vectors using variables as endpoints

When attempting to create a vector 't' using the following code:
for t = RSLT.lag_min+1:RSLT.date_ct;
I receive the following error:
Error using :
Colon operands must be in the range of the data type.
RSLT is a 1x1 structwith 18 fields (lag_min and date_ct being among them). Is it feasible to create vector using two variables?

댓글 수: 2

What data type (class) are RSLT.lag_min and RSLT.date_ct? Your syntax should work for most, but I'm guessing perhaps your endpoints are different classes that are perhaps not compatible when one is recast to the other.
The RSLT.lag_min is a int8 and the RSLT.date_ct is a double. I just converted both objects to doubles. Thanks, I was clearly overthinking.

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

답변 (1개)

John BG
John BG 2016년 4월 26일

0 개 추천

In MATLAB, if you want to use a structure called RSLT that has fields .lag_min and .date_ct first define them like RSLT.lag_min=1 RSLT.date_ct=2
The error message you receive is regarding the . used in MATLAB as element wise to whatever operator preceding.
For instance
A=randi(10,4,4)
A =
2 1 5 2
2 10 4 8
3 10 10 4
5 5 4 3
B=randi([-5 5],4,4)
B =
-1 5 -2 -4
-4 1 4 2
-4 -5 -5 3
5 -3 -5 2
A*B
=
-16 -20 -35 13
-18 -24 -24 40
-63 -37 -36 46
-26 1 -25 8
A.*B
=
-2 5 -10 -8
-8 10 16 16
-12 -50 -50 12
25 -15 -20 6
I applies to all basic operations .+ .- .* and ./
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2016년 4월 25일

댓글:

2016년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by