Creating vectors using variables as endpoints

2 ビュー (過去 30 日間)
Robert Garrison
Robert Garrison 2016 年 4 月 25 日
コメント済み: Robert Garrison 2016 年 4 月 26 日
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 件のコメント
Kelly Kearney
Kelly Kearney 2016 年 4 月 26 日
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 2016 年 4 月 26 日
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 日
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by