I get the following error message: "'Value' must be a double scalar." in appdesigner

2 ビュー (過去 30 日間)
Shanice Steinecke
Shanice Steinecke 2023 年 7 月 19 日
編集済み: Stephen23 2023 年 7 月 19 日
In my appdesigner code I want to get some values from my excel sheet (these values depend on the choice of the list box item):
if value == '2'
F = readtable("CO2_neu.xlsx","Sheet","List","Range","E4");
app.weight_1.Value = double(F.(1));
...
elseif value == '7'
G = readtable("CO2_neu.xlsx","Sheet","List","Range","E9");
app.weight_1.Value = double(G.(1));
end
For the value in cell E9 everything works and the respective value is displayed in my app. For all the other values from E4 - E8 I get the error message: 'Value' must be a double scalar even though these are also just numbers that I entered into the excel sheet and I use the exact same code to get them. Here you can see the excel sheet.
As the code works for the value in E9, I don't understand what the error is for the other cells?
I would be really grateful if someone could help me to fix this error!
  1 件のコメント
Stephen23
Stephen23 2023 年 7 月 19 日
編集済み: Stephen23 2023 年 7 月 19 日
Rather than using EQ to compare text like this:
if value == '2'
I strongly recommend that you use STRCMP or something similar. Or even SWITCH. Note that you could anyway replace that entire IF/ELSEIF... by defining the Range in terms of that value. Perhaps something like this:
N = 2;
R = "E"+(N+2);
T = readtable("CO2_neu.xlsx","Sheet","List","Range",R)

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

回答 (1 件)

VBBV
VBBV 2023 年 7 月 19 日
編集済み: VBBV 2023 年 7 月 19 日

Try using readmatrix function instead of readtable

  3 件のコメント
Shanice Steinecke
Shanice Steinecke 2023 年 7 月 19 日
編集済み: Shanice Steinecke 2023 年 7 月 19 日
When using readmatrix I get the same error
VBBV
VBBV 2023 年 7 月 19 日
編集済み: VBBV 2023 年 7 月 19 日

Ok. Perhaps you are using a small case value instead of Value for other cells. Can you check once ? Also check if the remaining cells have any characters or ASCII symbols inside them

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by