How to take multiple input using Edit Field (Text), MATLAB app designer?
14 views (last 30 days)
Show older comments
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 Comments
Rik
on 8 Mar 2023
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)
Accepted Answer
Rik
on 8 Mar 2023
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 Comments
More Answers (0)
See Also
Categories
Find more on Create Custom UI Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!