Creating vectors using variables as endpoints

5 visualizzazioni (ultimi 30 giorni)
Robert Garrison
Robert Garrison il 25 Apr 2016
Commentato: Robert Garrison il 26 Apr 2016
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 Commenti
Kelly Kearney
Kelly Kearney il 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.
Robert Garrison
Robert Garrison il 26 Apr 2016
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.

Accedi per commentare.

Risposte (1)

John BG
John BG il 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

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by