Hi,
I'm the beginner in using GUI MATLAB and need some help. I did some coding in GUI main_OpeningFcn to solve the similar coding in m-file. That coding is the main coding for my GUI, and the result depends on the user selection.
Then, I try to use pop-menu to display the result on the axes according the selection chosen in the pop-up menu. Each selection item from pop-up menu has its own .mat file and solve the algorithm that I code according to which item I selected.The result will display on the axes in GUI.
This is my coding in m-file:
function LBP_FBP_YAW_comsol_SM
clc, clear all, close all;
%each projection e1 till e16 from COMSOL in cell form :EachProj
load('EveryProjection.mat');
% ---------- Dot product to get each pairing projection -----------
i=1;
for i=1:16 %eliminate NAN values for each projection,e1 to e16
e=EachProj{1,i};
d=isnan(e);
e(d)=0;
EachProj{1,i}=e;
end
for i=1:16;
m1=EachProj{1,i};
for j=1:16
m2=EachProj{1,j};
c=m1.*m2; % Do the element multiplication to get Ei,j
E{i,j}=c;
end
end
%-------- Total Map/ Weight Balanced Map----------------------------------
WBMap = zeros(128);
for n=1:16;
for m=1:16;
WBMap = WBMap + E{n,m}; %%%Add coding for WBMap..x perlu load file WBMap yg buat cara panjang
end
end
%%%for filter matrix;
b = max(WBMap(:)); % choose max magintude pixel in total map
f = b./WBMap; % then, divide with total map to get the filter matrix
%------------- Normalize each pair projection,NormEi,j--------------------
for i=1:16;
for j=1:16
N{i,j} = E{i,j}./WBMap;
end
end
%%-------------------- LINEAR BACK PROJECTION(LBP)-----------------------
disp('Displaying Tomogram...');
load('SensorLossE1110mm.mat');
Attenuate_xy = SLe1110mm ; Resolution = 128; % --- IMAGE PIXEL SIZE
DispMap = zeros(Resolution); %view = 1;
for Tx = 1:16;
for Rx = 1:16;
DispMap = DispMap + (Attenuate_xy(Rx,Tx) * N{Rx, Tx}); %%%coding for getting LBP
end
end
%%------- coding to get the FILTERED BACK PROJECTION (FBP) algorithm ------
DispMapFBP = zeros(Resolution); %view = 1;
DispMapFBP = f .* DispMap; %%%FBP coding; filter matrik x LBP
% ----- DISPLAY TOMOGRAM RESULT--------------------------------------------
imagesc(DispMapFBP),imagesc(DispMap), shading interp; N = Resolution; r = N/2;
% figure('Name','TEST','NumberTitle','off')
Clim = max(DispMapFBP(:));
Clim = max(DispMap(:));
%%%%%%%Plot figure LHS for FBP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('Name','Filtered Back Projection','NumberTitle','off')
subplot(1,2,1)
pcolor(DispMapFBP); axis square, axis on; %M1 = mask_im(M1,N,r);
CircleBoarder.displayTomo(DispMapFBP, Resolution, Clim); %---- to standardized
set(gca,'YDir','normal'); % To invert the imagesc plot coz imagesc plot top to bottom
caxis([0, 0.14])
colorbar;
%%%%%%%Plot figure RHS for LBP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('Name','Linear Back Projection','NumberTitle','off')
subplot(1,2,2)
pcolor(DispMap); axis square, axis on; %M1 = mask_im(M1,N,r);
CircleBoarder.displayTomo(DispMap, Resolution, Clim); %---- to standardized
set(gca,'YDir','normal'); % To invert the imagesc plot coz imagesc plot top to bottom
caxis([0, 0.014])
colorbar;
function a=mask_im(a,M,r)
for i=1:M
for j=1:M
if sqrt((i-M/2)^2+(j-M/2)^2)>=r
a(i,j)=0;
end
end
end
Then, I try to use the coding in GUI function OpeningFCn:
% --- Executes just before Noninvasive_ERT_new3 is made visible.
function Noninvasive_ERT_new3_OpeningFcn(hObject, eventdata, handles, varargin)
global DispMap;
global Attenuate_xy;
global DispMapFBP;
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Noninvasive_ERT_new3 (see VARARGIN)
% Choose default command line output for Noninvasive_ERT_new3
handles.output = hObject;
%each projection e1 till e16 from COMSOL in cell form :EachProj
singleProj=load('EveryProjection.mat');
SP=singleProj.EachProj; %SP=single projection
% ---------- Dot product to get each pairing projection -----------
i=1;
for i=1:16 %eliminate NAN values for each projection,e1 to e16
e=SP{1,i};
d=isnan(e);
e(d)=0;
SP{1,i}=e;
end
for i=1:16;
m1=SP{1,i};
for j=1:16
m2=SP{1,j};
c=m1.*m2; % Do the element multiplication to get Ei,j
E{i,j}=c;
end
end
%-------- Total Map/ Weight Balanced Map----------------------------------
WBMap = zeros(128);
for n=1:16;
for m=1:16;
WBMap = WBMap + E{n,m}; %%%Add coding for WBMap..x perlu load file WBMap yg buat cara panjang
end
end
%%%for filter matrix;
b = max(WBMap(:)); % choose max magintude pixel in total map
f = b./WBMap; % then, divide with total map to get the filter matrix
%------------- Normalize each pair projection,NormEi,j--------------------
for i=1:16;
for j=1:16
N{i,j} = E{i,j}./WBMap;
end
end
%%-------------------- LINEAR BACK PROJECTION(LBP)-----------------------
disp('Displaying Tomogram...');
Attenuate_xy = get(handles.position_select, 'string') ; Resolution = 128; % --- IMAGE PIXEL SIZE
handles.Attenuate_xy=Attenuate_xy;
DispMap = zeros(Resolution); %view = 1;
for Tx = 1:16;
for Rx = 1:16;
DispMap = DispMap + (Attenuate_xy(Rx,Tx) * N{Rx, Tx}); %%%coding for getting LBP
handles.DispMap=DispMap;
end
end
%%------- coding to get the FILTERED BACK PROJECTION (FBP) algorithm ------
DispMapFBP = zeros(Resolution); %view = 1;
DispMapFBP = f .* DispMap; %%%FBP coding; filter matrik x LBP
handles.DispMapFBP=DispMapFBP;
% ----- DISPLAY TOMOGRAM RESULT--------------------------------------------
shading interp; N = Resolution; r = N/2;
Clim = max(DispMapFBP(:));
Clim = max(DispMap(:));
image1= subplot(2,1,1, 'Parent',handles.image_axes);
pcolor(image1,handles.DispMapFBP); axis square, axis on; %M1 = mask_im(M1,N,r);
CircleBoarder.displayTomo(DispMapFBP, Resolution, Clim); %---- yg ni bila letak comment wrna sam cm yg sblh kanan,So solution re-range color bar sblh kanan
set(gca,'YDir','normal'); % To invert the imagesc plot coz imagesc plot top to bottom
caxis([0, 1])
colorbar;
image2= subplot(2,1,2, 'Parent',handles.image_axes);
pcolor(image2,handles.DispMap); axis square, axis on; %M1 = mask_im(M1,N,r);
CircleBoarder.displayTomo(DispMap, Resolution, Clim); %---- yg ni bila letak comment wrna sam cm yg sblh kanan,So solution re-range color bar sblh kanan
set(gca,'YDir','normal'); % To invert the imagesc plot coz imagesc plot top to bottom
caxis([0, 1])
colorbar;
function a=mask_im(a,M,r)
for i=1:M
for j=1:M
if sqrt((i-M/2)^2+(j-M/2)^2)>=r
a(i,j)=0;
end
end
end
Next,from pop-menu callback function:
% --- Executes on selection change in position_select.
function position_select_Callback(hObject, eventdata, handles)
% hObject handle to position_select (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns position_select contents as cell array
% contents{get(hObject,'Value')} returns selected item from position_select
%gets the selected option
switch get(handles.position_select,'Value')
case 'center' % select center phantom
datastruct=load('SensorLossCenter20mmComsol221015.mat');
SL1 = datastruct.SL20mmcentercomsol;
handles.SL1=SL1;
handles.Attenuate_xy=handles.SL1;
case 'single' % select single phantom
datastruct=load('SensorLossE1110mm.mat');
SL2 = datastruct.SLe1110mm;
handles.SL2=SL2;
handles.Attenuate_xy=handles.SL2;
case 'double' % select double phantoms
case 'triple' % select triple phantoms
case 'multiple' % select multiple phantoms
otherwise
end
% Update handles structure
guidata(hObject, handles);
However, when I run the GUI itself didnt appears and the error shown in command window:
>> Noninvasive_ERT_new3
Displaying Tomogram...
Undefined function 'mtimes' for input arguments of type 'cell'.
Error in Noninvasive_ERT_new3>Noninvasive_ERT_new3_OpeningFcn (line 121)
DispMap = DispMap + (Attenuate_xy(Rx,Tx) * N{Rx, Tx}); %%%coding for getting LBP
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Noninvasive_ERT_new3 (line 42)
gui_mainfcn(gui_State, varargin{:});
What is it mean by undefined 'mtimes'? Or I cant use that '*' symbol? Is it correct the handles that I'm used in the coding?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de En. de 2016

0 votos

In your file SensorLossE1110mm.mat, the variable SLe1110mm is a cell array, but you are treating it as if it is a double.

7 comentarios

yasmin
yasmin el 19 de En. de 2016
What do you mean by 'treating it as if it is a double'? So, what should I do so that I can use it as the cell?
Walter Roberson
Walter Roberson el 19 de En. de 2016
Editada: Walter Roberson el 19 de En. de 2016
Your line
DispMap = DispMap + (Attenuate_xy(Rx,Tx) * N{Rx, Tx}); %%%coding for getting LBP
extracts a particular cell from the cell array N and multiplies it by whatever is in Attenuate_xy(Rx,Tx) . But Attenuate_xy is a cell array, and when you use () to index a cell array, even if you only access a single cell of it, the result is a cell array. So you are trying to multiply that cell array by whatever was retrieved from N{Rx,Tx} but multiplying cell arrays is not defined.
If the contents inside Attenuate_xy(Rx,Tx) happens to be either a scalar numeric value or else a vector or 2D array that has the same number of columns as N{Rx,Tx} has rows, then you could code
DispMap = DispMap + (Attenuate_xy{Rx,Tx} * N{Rx, Tx}); %%%coding for getting LBP
This would also be valid for the case where the contents of Attenuate_xy{Rx,Tx} is a numeric array of any dimension if N{Rx,Tx} happens to be a numeric scalar.
If Attenuate_xy{Rx,Tx} is a numeric vector or array the exact same size as N{Rx,Tx} then you could code
DispMap = DispMap + (Attenuate_xy{Rx,Tx} .* N{Rx, Tx}); %%%coding for getting LBP
yasmin
yasmin el 19 de En. de 2016
Ok, thank you for your detail explanation.
But why in m-file the code is successful even I'm using the same method?
yasmin
yasmin el 19 de En. de 2016
I have follow with the advice however, the error shown:
Displaying Tomogram...
Error using *
Inner matrix dimensions must agree.
Error in Noninvasive_ERT_new3>Noninvasive_ERT_new3_OpeningFcn (line 120)
DispMap = DispMap + (Attenuate_xy{Rx,Tx} * N{Rx, Tx}); %%%coding for getting LBP
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Noninvasive_ERT_new3 (line 42)
gui_mainfcn(gui_State, varargin{:});
I think because of the mismatch matrix. Or is it because of other problem?
The array of Attenuate_xy is 16 (row)x16(column) matrix. There is a several files of this that I save as .mat for each file. The cell for N{i,j} is 1x16 (1 row, 16 coloumn) and each of array matrix inside the cell is 128x128 matrix.
Walter Roberson
Walter Roberson el 19 de En. de 2016
Because you have coded your callbacks incorrectly.
When you get() the 'Value' of a uicontrol() listbox or popup, then the result you get is the numeric index of the choice the user made. In your position_select_Callback you are switch'ing on that Value and expecting the result to be a string such as 'multiple' but it is not going to be: it will be the index such as 3
When you get() the 'String' of a uicontrol() listbox or popup, then the result you get is (usually) a cell array of strings, one entry for each potential choice. This is all of the choices together. If you get the String property and you index it by the Value property then you will get the string chosen.
The Attenuate_xy = SLe1110mm that you have in your function LBP_FBP_YAW_comsol_SM is not the same as the Attenuate_xy in your function Noninvasive_ERT_new3_OpeningFcn . In that function you declare that variable to be global, but global variables are only global to routines that "global" them by name.
In Noninvasive_ERT_new3_OpeningFcn you assign to handles.Attenuate_xy but you do not use guidata(hObject, handles) before the end of the routine, so your changes to handles are going to be lost. And what you assign is the faulty result of the String property of handles.position_select and as discussed above that is going to be a cell array of strings, and you cannot multiply cell arrays of strings.
In your position_select_Callback in some cases you assign actual data to handles.Attenuate_xy and you do use guidata() so that would be remembered. On the other hand that is the routine where you getting the Value and then assuming it is a string.
Note that position_select_Callback is not going to be called before Noninvasive_ERT_new3_OpeningFcn
Thus, you do not need to change the
DispMap = DispMap + (Attenuate_xy(Rx,Tx) .* N{Rx, Tx}); %%%coding for getting LBP
It is fine in itself. What you need to change is the way you get the appropriate data to Attenuate_xy in Noninvasive_ERT_new3_OpeningFcn before you use it.
It would not be good practice to have both Noninvasive_ERT_new3_OpeningFcn and position_select_Callback have the same code to decide what to load into Attenuate_xy . You should have the decision logic in one place, a function that you invoke from both places.
function position_select_Callback(hObject, eventdata, handles)
% hObject handle to position_select (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns position_select contents as cell array
% contents{get(hObject,'Value')} returns selected item from position_select
handles = load_attenutate(handles);
guidata(hObject, handles);
function handles = load_attenuate(handles);
%gets the selected option
choice_strings = get(handles.position_select, 'String');
choice_value = get(handles.position_select,'Value');
chosen = choice_strings{choice_value};
switch chosen
case 'center' % select center phantom
datastruct = load('SensorLossCenter20mmComsol221015.mat');
SL1 = datastruct.SL20mmcentercomsol;
handles.SL1 = SL1;
handles.Attenuate_xy = handles.SL1;
case 'single' % select single phantom
datastruct = load('SensorLossE1110mm.mat');
SL2 = datastruct.SLe1110mm;
handles.SL2 = SL2;
handles.Attenuate_xy = handles.SL2;
case 'double' % select double phantoms
handles.Attenuate_xy = []; %replace by real code
case 'triple' % select triple phantoms
handles.Attenuate_xy = []; %replace by real code
case 'multiple' % select multiple phantoms
handles.Attenuate_xy = []; %replace by real code
otherwise
warning('Unknown position_selection string!');
if ~isfield(handles, Attenuate_xy)
handles.Attenuate_xy = [];
end
end
%do not do guidata() here!!
and in Noninvasive_ERT_new3_OpeningFcn instead of looking at position_select, call
handles = load_attenuate(handles);
after which handles.Attenuate_xy will exist (and possibly be empty if the data could not be loaded.)
Remember to guidata(hObject, handles) at the end of Noninvasive_ERT_new3_OpeningFcn
yasmin
yasmin el 20 de En. de 2016
Hi, Thank you for a very clear explanation.
I have tried follow your advice but is still consist of error. I did not know how to troubleshoot anymore.
The error was still similar. Even though I change it into '.*' or '* '; the error keep shown in command window. I'm also put the guidata(hObject,handles) at the end of Noninvasive_ERT_new3_OpeningFcn as what you're adviced. But, the same problem still occured.
Displaying Tomogram...
Undefined function 'mtimes' for input arguments of type 'cell'.
Error in Noninvasive_ERT_new3>Noninvasive_ERT_new3_OpeningFcn (line 109)
DispMap = DispMap + (Attenuate_xy(Rx,Tx) * N{Rx, Tx}); %%%coding for getting LBP
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Noninvasive_ERT_new3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Could you advice/guide what should I do to get the simplest way to code the GUI? I attach my GUI file for your further reference.
Walter Roberson
Walter Roberson el 20 de En. de 2016
In function Noninvasive_ERT_new3_OpeningFcn delete
global Attenuate_xy;
and delete
handles.Attenuate_xy=Attenuate_xy;
Then right after
handles = load_attenuate(handles);
add
Attenuate_xy = handles.Attenuate_xy;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

el 19 de En. de 2016

Comentada:

el 20 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by