Creating vectors using variables as endpoints
2 views (last 30 days)
Show older comments
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 Comments
Kelly Kearney
on 26 Apr 2016
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.
Answers (1)
John BG
on 26 Apr 2016
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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!