How to take multiple input using Edit Field (Text), MATLAB app designer?

I have 25 images (numbered 1 to 25) as output from which I want the user to select the ones that is needed to be manually edited by entering the number of the image, like 1, 2, 15, 21 using Edit Field (Text) in MATLAB app designer.
In the simple coding format I did the following,
answer = questdlg('Do you want to adjust outline manually','Manual outline','Yes','No','No');
switch answer
case 'Yes'
prompt = {'Enter well number to adjust:'};
dlgtitle = 'Well number';
dims = [1 50];
definput = {'1,5,8,etc.'};
well_pos = inputdlg(prompt,dlgtitle,dims,definput);
[output_BF_new, para_BF_new] = manual_adjust(Well, well_pos, output_BF,para_BF);
figure, montage(output_BF_new)
case 'No'
disp('Image analysis complete')
para_BF_new = para_BF; output_BF_new = output_BF;
end
--------------------------------------------------------------------------------------------------------------------
However, in case of MATLAb app designer when I do the following,
function ManualButtonPushed(app, event)
%app.well_pos = app.WellPositionEditField.Value{1};
%app.well_pos(~isstrprop(app.well_pos,'digit')) = ' '; %replace non-numeric characters with empty space
%vec = str2double(strsplit(strtrim(str))); % trim white space and convert to numeric
app.well_pos = str2num(app.WellPositionEditField.Value{1});
%app.well_pos = str2double(strsplit(app.WellPositionEditField.Value(1)));
[output_BF_new, para_BF_new] = manual_adjust(app.Well, app.well_pos, app.output_BF, app.para_BF);
%figure, montage(output_BF_new)
montage(app.output_BF_new, 'Parent', app.UIAxes_2)
axis(app.UIAxes_2, 'tight');
end
The following error is generated:
Brace index is not supported for variables of this type.
--------------------------------------------------------------------------------------------------------------------
The code for the function is:
function [array, param] = manual_adjust(Well, well_pos, array, param)
mod_pos = str2num(well_pos{1});
for b=1:length(mod_pos)
image = Well{mod_pos(b)};
black = logical(zeros(size(image)));
%figure,imshow(image);
[myobj,xs,ys] = freehanddraw(gca,'color','r','linewidth',2);
boundary = [uint8(ys), uint8(xs)];
Par = blob_parameters(xs, ys);
param(mod_pos(b),1:5) = Par;
BW8 = select_bound(black, boundary);
BW8f = imfill(BW8,'holes');
intensity = regionprops(BW8f, image, 'MeanIntensity');
param(mod_pos(b),6) = intensity.MeanIntensity;
BWoutline3 = bwperim(BW8f);
array{mod_pos(b)} = imoverlay(image,BWoutline3,'red');
end

댓글 수: 4

Where exactly is the error generated? Does that happen in the external function or in the callback itself?
Based on the number of different approaches in your commented code, you seem to have some trouble extracting a numeric value from your edit field.
app.well_pos = str2num(app.WellPositionEditField.Value{1});
Here is the error occuring. I tried in different ways (in comments) but the error remains same.
I once changed the {} in the above code to () then it shows same error in call back function's line,
mod_pos = str2num(well_pos{1});
Please have a read here to learn how to format your posts.
Before doing multiple operations in a single line, first you must find out what the class, size, and contents of your variable are. So what do these lines return?
Val=app.WellPositionEditField.Value;
class(Val),size(Val),disp(Val)
Here is the output for ur mentioned code,
ans =
'char'
ans =
1 10
1, 2, 3, 7

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2023년 3월 8일

0 개 추천

Your function lacks any form of documentation, so a user must just guess what the required input format is. In the case of well_pos the expected input is apparently a cell array, where the first element must contain a char vector that str2num can parse and will result in positive integers that will index the cell array Well.
So, what you need to do is either
  • Edit the function so it doesn't have that requirement
  • Or use app.well_pos = {app.WellPositionEditField.Value};
Just remember that you really should document what your function is doing. You won't be able to remember in 2 months, nor will anyone who you share this code with. A good target is to have as much comments as you have code. That will be overkill, but if that is your target, you will probably end up with a reasonable amount.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기

질문:

2023년 3월 8일

답변:

Rik
2023년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by