how to give range in xlsread using edit text field in app designer?

i was to read a coloumn from xlsx file which is simple to implement as following
columnB = xlsread(myExample.xlsx,'B:B'); % this works
but i m designing a app in appdesigner, i want to give option to user to input desired column name, i tryed this through
% lets suppose my text edit field is named as app.Columneditfield
columnB = xlsread(myExample.xlsx,'app.Columneditfield.Value:app.Columneditfield.Value');
% this gives error not a valid range
% because when '' is used to define range it does not pick >>app.Columneditfield.Value<<
% kindly guide

 採用された回答

Rik
Rik 2022 年 1 月 7 日

1 投票

Assuming app.Columneditfield.Value is already a char, you can simply create the range like this:
Range=[app.Columneditfield.Value ':' app.Columneditfield.Value];
columnB = xlsread('myExample.xlsx',Range);

11 件のコメント

taimour sadiq
taimour sadiq 2022 年 1 月 7 日
Thanks i will update you soon after trying the guidelines.
taimour sadiq
taimour sadiq 2022 年 1 月 10 日
after weekend i m again on code, i think i m making some mistake in defining app.Columneditfield.Value as a char
when i simple use the below code as u guided
Range=[app.Columneditfield.Value ':' app.Columneditfield.Value];
columnB = xlsread('myExample.xlsx',Range);
it gives error "a quoted character vector is unterminated" and highligh text after :
can u little eloborate further that how may i define app.Columneditfield.Value as a char
i also tried following
char = app.Columneditfield.Value
char(app.Columneditfield.Value)
coloumn = 'app.Columneditfield.Value'
Rik
Rik 2022 年 1 月 10 日
What class is app.Columneditfield.Value? I don't immediately see how this code can result in this error.
taimour sadiq
taimour sadiq 2022 年 1 月 10 日
編集済み: taimour sadiq 2022 年 1 月 10 日
Dear Rik i may not be able to properly answer your question that which class is app.Columneditfield.Value... one app.UIAxes i put an "EditField Text" icon and write xlread read code in callback... to simple the scenerio i can share a proper working file after few hours which inlcude the code in appdesigner also some screen shot to illustrate the issue.
Rik
Rik 2022 年 1 月 10 日
You can put this line in your code to easily check:
uialert(app.UIFigure,sprintf('class name is %s',class(app.Columneditfield.Value)),'')
taimour sadiq
taimour sadiq 2022 年 1 月 11 日
appreciate ur guidence, this line also giving a error in code before execution
uialert(app.UIFigure,sprintf('class name is %s',class(app.Columneditfield.Value)),'')
>> Invalid syntax at 'class'. A '(' might be missing a closing')'
Rik
Rik 2022 年 1 月 11 日
The actual error must be somewhere else, because this line of code is correct. Check the rest of the code for mismatched parentheses and other syntax errors.
taimour sadiq
taimour sadiq 2022 年 1 月 11 日
yes ur assumption about error is possible, i will review the whole code and will update hopefully tommorow.
taimour sadiq
taimour sadiq 2022 年 1 月 12 日
i have attached a demo app fie to illustrate... Kindly guide further... class name is char
Rik
Rik 2022 年 1 月 12 日
You forgot to leave in the spaces:
%You wrote:
Range = [app.ColumnEditField.Value':'app.ColumnEditField.Value];
%You should have written:
Range = [app.ColumnEditField.Value ':' app.ColumnEditField.Value];
taimour sadiq
taimour sadiq 2022 年 1 月 12 日
i really made a silly mistake.. appreciate ur patience... Now it works fine according to my requirement.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2019a

質問済み:

2022 年 1 月 7 日

コメント済み:

2022 年 1 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by