have 2 questions in app designer. Need to convert a char array to a string and also extract coordinates on mouse up event

2 views (last 30 days)
attached is a QA inspection tool
I am having problems with 2 things.
  1. We need to printout the file name (file name of the image that is loaded at the start) into the GUI text box (filenameeditfield). I keep getting errors when converting the char array to a string. I have tried about 3 or 4 different examples and none seem to work and Im so confused as this should be straight forward?
see function "openfile". A few tries that were made that dont work are shown below.
% app.FileNameEditField.Value =string(strjoin(cellstr(file))) ; strcat(file{:});
% app.FileNameEditField.Value = convertCharsToStrings(file)
% app.FileNameEditField.Value = string(file);
  1. The 2nd part of the QA is finding the center point of a round beam on a image (loaded from the file). The user should click the button to find the center and then an outline is made around the beam, showing the pereimter of the beam with respect the center point selectedf. The points currently are registered right when the user clicks the first time. However, its hard for the user to click right in the center on the first shot. I would like the user to be able to use a mouse up rather than mouse down event so they can move (slide) the center position around to visually find the center. I cant figure out how to do this.
This is under function FindCenterButtonPushed(app, event)
The point is drawn here: roiPOC = drawpoint(app.UIAxes_2); %Use Mouse To Select a
I attached the file and an example of an image we are processing.
Really appreciate the help in advance
  1 Comment
Walter Roberson
Walter Roberson on 3 Mar 2025
You indicate that file is a char array. Is it a char array with multiple rows?
If file is a single row character vector, then
app.FileNameEditField.Value = file;
should work.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 4 Mar 2025
Edited: Cris LaPierre on 4 Mar 2025
Question 1 - Why are you getting the error 'Value' must consist of valid text as specified by 'InputType'?
This is because the EditField InputType has been set to 'alphanumeric'. This means Value can only contain text and digits. Your filename contains hyphens and a period. Set the InputType to 'text'. Once changed, you can assign either a char vector or a string scalar as the Value of the EditField.
Question 2 - You'll never be able to consistenly select the exact center of the circle. Why not just adjust the ROI outline after it is drawn? Move the cursor until it changes to coordinates, then drag the circle until it is positioned where you want. You could add a listener function to your app to detect when this moves and update the center location accordingly. See this example.
  1 Comment
Cris LaPierre
Cris LaPierre on 4 Mar 2025
You might also consider automating finding the center of your circle. Here's a quick and dirty approach just to demonstrate, with the center calculated using regionprops. Compare the resulting (X,Y) of the centroid with those you would select using the app.
img = imread('25180-IRR-1329 img005.jpg');
% Adjust data to span data range.
img = imadjust(img);
% Threshold image with global threshold
BW = imbinarize(im2gray(img));
% Invert mask
BW = imcomplement(BW);
% Close mask with default
radius = 10;
decomposition = 8;
se = strel('disk', radius, decomposition);
BW = imclose(BW, se);
% Create masked image.
maskedImage = img;
maskedImage(~BW) = 0;
% Compute selected properties for each region
stats = regionprops(BW,["Centroid","Area"]);
% Remove ROIs with small area
smallIdx = [stats.Area]<100000;
stats(smallIdx) = [];
% Show centroid location for all remaining ROIs
figure
centroids = cat(1,stats.Centroid)
centroids = 1×2
1.0e+03 * 2.3566 2.1099
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
imshow(BW)
hold on
plot(centroids(:,1),centroids(:,2),'r*')
hold off

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!