How to create a GUI in matlab?

Hello everybody,
i am not very experienced in matlab.
I have to create a GUI that a gui that should make me enter:
input: a file (of any extension) and the numerical values of some variables (ex: x coordinates, y coordinates, size_map)
output: an .hdr file that contains these numeric values associated with the input file
i'm using gdal in matlab
How can I do?

4 Comments

It is not clear, what you call "mask" and how it is related to the "input file". The operator "->" is not defined in Matlab also. So what does "-> (x_min, x_max, y_min, y_max, pixel_size)" mean?
Add more details by editing the question, not by appending comments. Thanks.
Thanks for the answer, i edited the question
Sounds like you totally overlooked or ignored my answer below. Why?
I'm sorry, I answered you

Sign in to comment.

Answers (1)

You forgot to attach your input file, probably because you never read the community guidelines or this link:
So if the file is a binary image, you can do
mask = imread(filename);
[rows, columns] = find(mask);
x_min = min(columns);
x_max = max(columns);
y_min = min(rows);
y_max = max(rows);
To get the pixel size you're going to have to get that somehow, like from spatial calibration or the header of the image. Otherwise, any spatial analysis will just give you results in pixels, which really doesn't have a size, or maybe you just want to consider it as 1. But if you want real world units, you have to calibrate like shown in my attached demo.

9 Comments

I apologize for the error.
My input file is a raster file.
This file must be loaded in input, together with the values of the 4 corners of the image (x_min, x_max, y_min, y_max).
This file must then be converted from latlog to utm / m and exported in .tif format
I would like to create a GUI with which to launch these commands
Admit it, you didnt' read the link I gave you. I can tell.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
i read, but i don't have an input file to attach.
As for the code, being a beginner, I have no idea how to write it and then develop a gui for it
@Harry Smith: You cannot provider an input file. The description of the GUI you want to create is very lean. It is not clear what exactly "the numerical values of some variables" and ".hdr file that contains these numeric values associated with the input file" exactly means.
You mention "gdal" but the readers have to guess, what this is and how it is related to your problem.
Again: Consider the tutorial concerning asking questions, which can be answered. Currently all we know, is that you want to create a specific GUI and that you are not sure how it should look like and what it should exactly do. BAsed on these details it is not possible to assist you.
Split the problem into small parts and solve one after the other. Start with deciding if you want to create a figure or uifigure, and if you want to create the GUI programmatically or using the tools GUIDE or AppDesigner. Then implement a button, which open a dialog for choosing a file.
If you have specific questions for this part of the solution, come back and ask again.
I am writing my reasoning here:
I have some variables: a, b, c, d, e
I would like to associate an alphanumeric value to these variables, creating an interactive table that the user can view, add the values he wants and save it in .txt format
I am attaching a code example I made:
%creating txt file
a=[];
b=[];
c=[];
fileID=fopen('file.txt','w');
fprintf(fileID,'a = %u\r\n',a);
fprintf(fileID,'b = %u\r\n', b);
fprintf(fileID,'c = %u\r\n',c);
%convert txt file into a table
table_filetxt=readtable(file);
%creating a gui for the table
fig = uifigure;
uit = uitable(fig,'Data',table_filetxt);
uit = uitable(fig);
uit.Data = table_filetxt;
uit.ColumnSortable = true;
uit.ColumnEditable = [true true true] %to edit the values a,b,c
the table is created and you can change the values, but I don't know how to save it
Try writetable if you want to save it to disk.
Thank you for your answer.
In this case i store the same .txt file that i created previously, because when i edit the values of my variables, the editing is not saved.
It should be. Write a small demo that proves this to me. Here are the steps you should do:
% Read your existing table.
t = readtable(filename)
% Now alter one field to have a different value.
t.Whatever(1) = someNewValue;
% Now call write table and save to a different text file.
filename2 = 'answers.txt'
writetable(t, filename2)
Then attach the code and both text files with the paperclip icon.
In this case it works, but I would like to be able to change the values at the graphical interface, not at the code level.
I attach the input file and my code:
file='fileinput.txt';
table_filetxt=readtable(fileinput);
fig = uifigure;
uit = uitable(fig,'Data',table_filetxt);
uit = uitable(fig);
uit.Data = table_filetxt;
uit.ColumnSortable = true;
uit.ColumnEditable = [false true true true];
fileinput2='fileinput2.txt'
writetable(table_filetxt,'fileinput2.txt');
A window opens with my table, I can modify the values, but not save it.
Instead, if you opened the table via workspace and changed the values, in that case it would save them.

Sign in to comment.

Asked:

on 13 Sep 2022

Commented:

on 15 Sep 2022

Community Treasure Hunt

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

Start Hunting!