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 个)

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 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by