How to I get the info from a designated cell from Excel when it is a string?

1 回表示 (過去 30 日間)
Jesse Finnell
Jesse Finnell 2023 年 6 月 6 日
編集済み: Cris LaPierre 2023 年 6 月 7 日
I have the following code:
Std = get(DB.Activesheet,'Range','C8');
if Std.Value == "DWA"
standard = 1-2.29*10^(-4)*(Depth.Value/3.2808)^2+9.19*10^(-3)*(Depth.Value/3.2808)
else
standard = 1
end
This returns the error "Dot indexing is not supported for variables of this type."
If I run the following code in the command window I receive the output needed.
>> Std.Value
ans =
'DWA'
How do I fix this to be able to test if the cell in the Excel spreadsheet contains that three letter string "DWA"?
  2 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 6 月 6 日
What line of code is throwing the error? Please share the entire error message (all the red text).
What if you try the following format instead?
Std = DB.ActiveSheet.get('Range','C8');
Jesse Finnell
Jesse Finnell 2023 年 6 月 6 日
編集済み: Jesse Finnell 2023 年 6 月 6 日
Here is the output from the command window
>> Std = get(DB.Activesheet,'Range','C8');
if Std.Value == 'DWA'
standard = 1-2.29*10^(-4)*(Depth.Value/3.2808)^2+9.19*10^(-3)*(Depth.Value/3.2808)
else
standard = 1
end
Dot indexing is not supported for variables
of this type.
If I change my code to what is suggested, I receive the same error.

サインインしてコメントする。

採用された回答

VBBV
VBBV 2023 年 6 月 6 日
編集済み: VBBV 2023 年 6 月 6 日
May be the error refers to the variable Depth for which there is no Value field..
Can you check whether its a simple variable or a struct variablle ? If its NOT struct then its likely to throw such error
if Std.Value == 'DWA'
standard = 1-2.29*10^(-4)*(Depth/3.2808)^2+9.19*10^(-3)*(Depth/3.2808)
% >> >>
else
standard = 1
end
  3 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 6 月 7 日
編集済み: Cris LaPierre 2023 年 6 月 7 日
What is the output if you run the following code? I'd run each line separately so you know which line of code any error messages belong to.
Std.Value
Depth.Value
standard = 1-2.29*10^(-4)*(Depth.Value/3.2808)^2+9.19*10^(-3)*(Depth.Value/3.2808)
Jesse Finnell
Jesse Finnell 2023 年 6 月 7 日
My failure to read closely was my problem. I had already converted the Depth variable to a double and the if loop fails because I was trying to index the value a second time. Thanks for the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by