open docx using popupmenu

Hi,
I am trying to open different docx files using a combination of four popupmenues in a gui and if statements.
For some reason, no matter what I choose in my popupmenus, I keep getting only the first file (10.12B.docx) opened.
Can someone tell why?
if (Z==2) && (PD(i)<30)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==2) && (PD(i)>=30)
RN=10.14;
winopen('10.14B.docx');
end
if (Z==3) && (PD(i)<30)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==4) && (PD(i)<30)
RN=10.14;
winopen('10.14B.docx');
end
if (Z==5) && (PD(i)<30)
RN=10.14;
winopen('10.14B.docx');
end
if (Z==6) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==6) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==6) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==6) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==7) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==7) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==7) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==8) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==8) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==8) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==9) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==9) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==9) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==10) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==10) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==10) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==10) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==11) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==11) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==11) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==11) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==12) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==12) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==12) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==12) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==13) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==13) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==13) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==13) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==14) && (PD(i)<20)
RN=10.3;
winopen('10.3C.docx');
end
if (Z==14) && (PD(i)>=20 && PD(i)<30)
RN=10.4;
winopen('10.4B.docx');
end
if (Z==14) && (PD(i)>=30)
RN=10.5;
winopen('10.5B.docx');
end
if (Z==15) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==15) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==15) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==15) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==16) && (PD(i)<20)
RN=10.3;
winopen('10.2C.docx');
end
if (Z==16) && (PD(i)>=20 && PD(i)<30)
RN=10.4;
winopen('10.9B.docx');
end
if (Z==16) && (PD(i)>=30)
RN=10.7;
winopen('10.10B.docx');
end
if (Z==17)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==18)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==19)
RN=10.13;
winopen('10.12B.docx');
end
if (Z==20)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==21)
RN=10.12;
winopen('10.12B.docx');
end

14 件のコメント

Rik
Rik 2020 年 4 月 14 日
Did you check the values of Z and PD(i)? It also looks like you should make all of these elseif instead. Then you can also add an else to catch unexpected values and mlint should be able to warn you about duplicate conditions.
Daniel Liberman
Daniel Liberman 2020 年 4 月 14 日
tried it, still I get only the first file open
Ankit
Ankit 2020 年 4 月 14 日
logic is working fine! I tried to change value of Z and PD, code open different word files. I think problem is with PD(i). Are you sure you are getting different PD(i)? Can you display PD(i) values in workspace and check again?
Rik
Rik 2020 年 4 月 14 日
What are the exact values of Z and PD(i) at the time of execution? Put a breakpoint just befor the first if you showed and execute this line:
clc,fprintf('Z=%.15f PD(i)=%.15f\n',Z,PD(i))
Daniel Liberman
Daniel Liberman 2020 年 4 月 15 日
I tried it, it says Z=2, Z is the value coming from my fourth popupmenu (meaning the number of option I chose, while the options are strings). Also, the options appearing in the fourth popupmenu are depended on the options chosen in the 3 previous ones if it matters.
Rik
Rik 2020 年 4 月 15 日
That is not the output of the line of code I posted. You think you may be withholding irrelevant information, but this is the key to your problem. If Z has a value of 2 and PD(i) a value below 30, then what you describe as a problem is the intended behavior of your code.
Daniel Liberman
Daniel Liberman 2020 年 4 月 17 日
It isn't since I get Z=2 no matter what I choose in popupmenu4, while Z should equal 2 only if I pick the first choice from popupmenu4
Geoff Hayes
Geoff Hayes 2020 年 4 月 17 日
Daniel - how is Z being set? Please copy and paste that code to this question.
Daniel Liberman
Daniel Liberman 2020 年 4 月 18 日
Geoff Hayes, here is my entire code, Z is set using popupmenu 3 (and not 4 like I said before). Z is used in both popupmenu 4 and pushbutton 1 callback functions, yet it seems to change value only at popupmenu 4 callback function:
function varargout = abdrapp(varargin)
% ABDRAPP MATLAB code for abdrapp.fig
% ABDRAPP, by itself, creates a new ABDRAPP or raises the existing
% singleton*.
%
% H = ABDRAPP returns the handle to a new ABDRAPP or the handle to
% the existing singleton*.
%
% ABDRAPP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ABDRAPP.M with the given input arguments.
%
% ABDRAPP('Property','Value',...) creates a new ABDRAPP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before abdrapp_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to abdrapp_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help abdrapp
% Last Modified by GUIDE v2.5 23-Mar-2020 13:03:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @abdrapp_OpeningFcn, ...
'gui_OutputFcn', @abdrapp_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before abdrapp is made visible.
function abdrapp_OpeningFcn(hObject, eventdata, handles, varargin)
% 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 abdrapp (see VARARGIN)
% Choose default command line output for abdrapp
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.popupmenu2,'Visible','Off');
set(handles.popupmenu3,'Visible','Off');
set(handles.popupmenu4,'Visible','Off');
set(handles.edit2,'Visible','Off');
set(handles.edit3,'Visible','Off');
set(handles.edit4,'Visible','Off');
set(handles.edit5,'Visible','Off');
set(handles.text3,'Visible','Off');
set(handles.text4,'Visible','Off');
set(handles.text5,'Visible','Off');
set(handles.pushbutton1,'Visible','Off');
% UIWAIT makes abdrapp wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = abdrapp_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
A=get(handles.popupmenu1,'Value');
switch A %Popupmenu1 options
case 2 %Popupmenu2, option1
set(handles.popupmenu2,'Visible','On');
x=get(handles.popupmenu2,'String');
x=[x(1) x(2) x(3) x(4)]; %Popupmenu2 options
set(handles.popupmenu2,'String',x);
case 3 %Popupmenu2, option2
set(handles.popupmenu2,'Visible','On');
x=get(handles.popupmenu2,'String');
x=[x(1) x(5) x(6) x(7) x(8) x(9)]; %Popupmenu2 options
set(handles.popupmenu2,'String',x);
end
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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 popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
A=get(handles.popupmenu1,'Value');%Aircraft
B=get(handles.popupmenu2,'Value');%Part
switch A
case 2 %Popupmenu1, option1
switch B
case 2 %Popupmenu2, option1
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(2) a(3) a(4) a(5)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 3 %Popupmenu2, option2
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(6) a(7) a(8) a(9)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 4 %Popupmenu2, option3
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(10) a(11)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
end
case 3 %Popupmenu1, option2
switch B
case 2 %Popupmenu2, option4
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(12) a(13) a(14)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 3 %Popupmenu2, option5
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(15) a(16)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 4 %Popupmenu2, option6
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(17) a(18)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 5 %Popupmenu2, option7
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(19)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
case 6 %Popupmenu2, option8
set(handles.popupmenu3,'Visible','On');
a=get(handles.popupmenu3,'String');
a=[a(1) a(20) a(21)];%Popupmenu3 options
set(handles.popupmenu3,'String',a);
end
end
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (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 popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
A=get(handles.popupmenu1,'Value'); %Popupmenu1
B=get(handles.popupmenu2,'Value'); %Popupmenu2
C=get(handles.popupmenu3,'Value'); %Popupmenu3
switch A
case 2 %Popupmenu1 option1
switch B
case 2 %Popupmenu2 option1
switch C
case 2 %Popupmenu3 option1
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(2)]; %Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('1.jpg');
imshow(l);
case 3 %Popupmenu3 option2
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(3)]; %Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('2.jpg');
imshow(l);
case 4 %Popupmenu3 option3
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(4)]; %Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('3.jpg');
imshow(l);
case 5 %Popupmenu3 option4
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(5)]; %Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('4.jpg');
imshow(l);
end
case 3 %Popupmenu2 option2
switch C
case 2 %Popupmenu3 option5
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(6) b(7) b(8) b(9)]; %Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('5.jpg');
imshow(l);
case 3 %Popupmenu3 option6
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(10)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('6.jpg');
imshow(l);
case 4 %Popupmenu3 option7
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(11)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('7.jpg');
imshow(l);
case 5 %Popupmenu3 option8
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(12)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('8.jpg');
imshow(l);
end
case 4 %Popupmenu2 option3
switch C
case 2 %Popupmenu3 option9
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(13) b(14) b(15) b(16)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('9.jpg');
imshow(l);
case 3 %Popupmenu3 option10
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(17) b(18)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('10.jpg');
imshow(l);
end
end
case 3 %Popupmenu1 option2
switch B
case 2 %Popupmenu2 option4
switch C
case 2 %Popupmenu3 option11
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(19) b(20)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('11.jpg');
imshow(l);
case 3 %Popupmenu3 option12
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(21) b(22)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('12.jpg');
imshow(l);
case 4 %Popupmenu3 option13
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(23) b(24) b(25) b(26)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('13.jpg');
imshow(l);
end
case 3 %Popupmenu2 option5
switch C
case 2 %Popupmenu3 option14
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(27) b(28)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('14.jpg');
imshow(l);
case 3 %Popupmenu3 option15
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(29) b(30) b(31)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('15.jpg');
imshow(l);
end
case 4 %Popupmenu2 option6
switch C
case 2 %Popupmenu3 option16
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(32)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('16.jpg');
imshow(l);
case 3 %%Popupmenu3 option17
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(33)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('17.jpg');
imshow(l);
end
case 5 %Popupmenu2 option7
switch C
case 2 %Popupmenu3 option18
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(34)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('18.jpg');
imshow(l);
end
case 6 %Popupmenu2 option6
switch C
case 2 %Popupmenu3 option19
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(35) b(36)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('19.jpg');
imshow(l);
case 3 %Popupmenu3 option20
set(handles.popupmenu4,'Visible','On');
b=get(handles.popupmenu4,'String');
b=[b(1) b(37)];%Popupmenu4 options
set(handles.popupmenu4,'String',b);
figure()
l=imread('20.jpg');
imshow(l);
end
end
end
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu4 (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 popupmenu4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu4
%set(handles.edit1,'Visible','On');
set(handles.edit2,'Visible','On');
set(handles.edit3,'Visible','On');
set(handles.edit4,'Visible','On');
set(handles.edit5,'Visible','On');
set(handles.pushbutton1,'Visible','On');
set(handles.text3,'Visible','On');
set(handles.text4,'Visible','On');
set(handles.text5,'Visible','On');
Z=get(handles.popupmenu3,'Value');
if (Z==2)
figure()
m=imread('5.3.2.jpg');
imshow(m);
end
if (Z==3)
figure()
m=imread('5.3.2.jpg');
imshow(m);
end
if (Z==4)
figure()
m=imread('5.3.2.jpg');
imshow(m);
end
if (Z==5)
figure()
m=imread('5.3.2.jpg');
imshow(m);
end
if (Z==6)
figure()
m=imread('5.3.3.jpg');
imshow(m);
end
if (Z==7)
figure()
m=imread('5.3.3.jpg');
imshow(m);
end
if (Z==8)
figure()
m=imread('5.3.3.jpg');
imshow(m);
end
if (Z==9)
figure()
m=imread('5.3.3.jpg');
imshow(m);
end
if (Z==10)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==11)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==12)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==13)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==14)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
if (Z==15)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
if (Z==16)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
if (Z==17)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==18)
figure()
m=imread('5.3.4.jpg');
imshow(m);
end
if (Z==19)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
if (Z==20)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
if (Z==21)
figure()
m=imread('5.3.5.jpg');
imshow(m);
end
% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Z=get(handles.popupmenu3,'Value');
n=get(handles.edit2,'String');
n=str2num(n);
i=0;
j=0;
PD=zeros;
Xvec=get(handles.edit3,'String');
Yvec=get(handles.edit4,'String');
dvec=get(handles.edit5,'String');
Xn=str2double(strsplit(Xvec{:},','));
Yn=str2double(strsplit(Yvec{:},','));
dn=str2double(strsplit(dvec{:},','));
S1=zeros;
S2=zeros;
D_overlap=zeros(6);
x_overlap=zeros(6);
y_overlap=zeros(6);
dis=zeros(6);
Dis=zeros(6);
th=0:pi/100:2*pi;
for i=1:n
for j=i+1:n
dis(i,j)=sqrt(((Xn(j)-Xn(i))^2)+((Yn(j)-Yn(i))^2));
if dis(i,j)<2*(dn(i)+dn(j))
D_overlap(i,j)=0.5*(dn(i)+dn(j))+dis(i,j);
x_overlap(i,j)=0.5*(Xn(i)+Xn(j));
y_overlap(i,j)=0.5*(Yn(i)+Yn(j));
else
D_overlap(i,j)=0;
x_overlap(i,j)=1e6;
y_overlap(i,j)=1e6;
end
end
end
S1=sum(D_overlap,2);
S2=sum(D_overlap);
for i=1:n
if S1(i)==0 && S2(i)==0
D_NOC(i)=dn(i); %Non Overlaping Circles
X_NOC(i)=Xn(i);
Y_NOC(i)=Yn(i);
else
D_NOC(i)=0; %Non Overlaping Circles
X_NOC(i)=1e6;
Y_NOC(i)=1e6;
end
end
for i=1:n
for j=i+1:n
for k=j+1:n
Dis(i,k)=sqrt(((x_overlap(i,k)-x_overlap(i,j))^2)+((y_overlap(i,k)-y_overlap(i,j))^2));
if Dis(i,k)<D_overlap(i,j)+D_overlap(i,k)
D_overlap(i,j)=Dis(i,k)+(D_overlap(i,j)+D_overlap(i,k))*0.5;
x_overlap(i,j)=0.5*(x_overlap(i,j)+x_overlap(i,k));
y_overlap(i,j)=0.5*(y_overlap(i,j)+y_overlap(i,k));
D_overlap(i,k)=0;
D_overlap(j,k)=0;
x_overlap(i,k)=1e6;
x_overlap(j,k)=1e6;
y_overlap(i,k)=1e6;
y_overlap(j,k)=1e6;
end
end
end
end
for i=1:n
for j=i+1:n
if x_overlap(i,j)==1e6 && y_overlap(i,j)==1e6
x_overlap(i,j)=0;
y_overlap(i,j)=0;
end
end
end
S3=sum(D_overlap);
S4=sum(x_overlap);
S5=sum(y_overlap);
for i=1:n
if S3(i)>0
PD(i)=S3(i);
PX(i)=S4(i);
PY(i)=S5(i);
elseif D_NOC(i)>0
PD(i)=D_NOC(i);
PX(i)=X_NOC(i);
PY(i)=Y_NOC(i);
else
PD(i)=0;
PX(i)=1e6;
PY(i)=1e6;
end
end
figure()
for i=1:length(PD)
if(PX(i)~=1e6)&&(PY(i)~=1e6)
for j=1:length(th)
X_circ(i,j)=PX(i)+0.5*PD(i)*cos(th(j));
Y_circ(i,j)=PY(i)+0.5*PD(i)*sin(th(j));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (Z==2) && (PD(i)<30)
RN=10.12;
winopen('10.12B.docx')
end
if (Z==2) && (PD(i)>=30)
RN=10.14;
winopen('10.14B.docx')
end
if (Z==3) && (PD(i)<30)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==4) && (PD(i)<30)
RN=10.14;
winopen('10.14B.docx');
end
if (Z==5) && (PD(i)<30)
RN=10.14;
winopen('10.14B.docx');
end
if (Z==6) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==6) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==6) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==6) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==7) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==7) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==7) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==8) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==8) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==8) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==9) && (PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==9) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==9) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==10) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==10) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==10) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==10) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==11) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==11) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==11) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==11) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==12) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==12) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==12) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==12) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==13) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==13) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==13) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==13) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==14) && (PD(i)<20)
RN=10.3;
winopen('10.3C.docx');
end
if (Z==14) && (PD(i)>=20 && PD(i)<30)
RN=10.4;
winopen('10.4B.docx');
end
if (Z==14) && (PD(i)>=30)
RN=10.5;
winopen('10.5B.docx');
end
if (Z==15) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==15) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==15) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
if (Z==15) && (PD(i)>=30)
RN=10.11;
winopen('10.11B.docx');
end
if (Z==16) && (PD(i)<20)
RN=10.3;
winopen('10.2C.docx');
end
if (Z==16) && (PD(i)>=20 && PD(i)<30)
RN=10.4;
winopen('10.9B.docx');
end
if (Z==16) && (PD(i)>=30)
RN=10.7;
winopen('10.10B.docx');
end
if (Z==17)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==18)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==19)
RN=10.13;
winopen('10.12B.docx');
end
if (Z==20)
RN=10.12;
winopen('10.12B.docx');
end
if (Z==21)
RN=10.12;
winopen('10.12B.docx');
end
plot(X_circ(i,:),Y_circ(i,:))
str=sprintf('%.2f',RN);
text(PX(i),PY(i),str)
grid on
hold on
end
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Daniel Liberman
Daniel Liberman 2020 年 4 月 18 日
Anybody? ^^
Rik
Rik 2020 年 4 月 18 日
Have you tried setting a breakpoint on the line that should set the value of Z? I don't see any indication in this code that Z is not set as it should.
You should also note that a lot of the GUIDE generated code isn't doing anything useful when it comes to explaining behavior. The last 6 functions in the code you posted could have been omitted.
Daniel Liberman
Daniel Liberman 2020 年 4 月 19 日
Walter Roberson
Walter Roberson 2020 年 4 月 20 日
??? You are manipulating the content of the menus available to the popup menus dynamically, but you expect to use the relative item numbers???
I advise you to rewrite your code so that it does not rely upon menu item positions, and instead pulls the relevant string content out and compares against that. If you do that, then you can probably skip most of your nested cases, which exist mostly to be able to make sense out of which menu items are currently active.
Rik
Rik 2020 年 4 月 20 日
I would strongly suggest you use the code Walter suggested. As you can see, your current code is difficult to debug.
On a related note: are you actually using your Matlab root folder as current directory? That is a really bad idea, since you could end up editing core Matlab files, which could result in corrupting your installation. If you enjoy installing Matlab often you can keep doing this, but otherwise I suggest you use a different folder.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 4 月 18 日

0 投票

if (Z==6) && (PD(i)<20)
RN=10.2;
winopen('10.2C.docx');
end
if (Z==6) && (PD(i)>=20 && PD(i)<30)
RN=10.9;
winopen('10.9B.docx');
end
if (Z==6) && (PD(i)>=30)
RN=10.10;
winopen('10.10B.docx');
end
Consider:
%first value is for PD < 20, second is for 20<=PD<30, third is PD>30
RNvals = [
nan, nan, nan;
10.12, 10.12, 10.14; %Z2
10.12, 10.12, nan; %Z3
10.14, 10.14, nan; %Z4
10.14, 10.14, nan; %Z5
10.2, 10.9, 10.10; %Z6
]
Files = {'', '', '';
'12B', '12B', '14B';
'12B', '12B', '14B';
'14B', '14B', '';
'2C', '9B', '10B';
}
PDidx = (PD(:) < 20)*1 + (20 <= PD(:) & PD(:) < 30) * 2 + (PD(:) > 30) * 3;
idx = sub2ind(size(RNvals), Z, PDidx);
RN = RNvals(idx);
nanidx = find(isnan(RN));
if ~isempty(nanidx)
badZ = Z(nanidx(1));
badPD = PD(nanidx(1));
error('Z == %d is not configured for PD of %g', badZ, badPD);
end
file_selection = strcat({'10.'}, Files(idx), {'.docx'});
cellfun(@(F) winopen(F), file_selection);
Vectorized, has error checking, detects combinations not configured for.
Anywhere in your code you have long chains of if/then, you should consider configuring through arrays.
Like your image reading: you can have an array of file names according to Z values, index it by Z, and read that file.

カテゴリ

ヘルプ センター および File ExchangeVariable Initialization についてさらに検索

質問済み:

2020 年 4 月 14 日

コメント済み:

Rik
2020 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by