Tag Archives: matlab
Reshape nested cell arrays into the a different nested cell array organization
Hello, I have a nested cell array that has been built up such that the first level cell array A is {691×1}; within each cell in A, there is a second level cell array B of {48×1}; lastly within each cell in B there is a third level nested cell array C of {2×1}.
I want to reshape the nested cell array structure such that it is now organized in the order of cell array B {48×1} first; second level cell array C {2×1} and lastly a third level cell array of A {691×1}.
Is there a way to take the original cell array and use a specific function (such as reshape) to get my desired new nested cell array from my current nested cell array?
have: A {691×1} –> B{48×1} –> C{2×1}
want: B{48×1} –> C{2×1} –> A {691×1}
Thanks!Hello, I have a nested cell array that has been built up such that the first level cell array A is {691×1}; within each cell in A, there is a second level cell array B of {48×1}; lastly within each cell in B there is a third level nested cell array C of {2×1}.
I want to reshape the nested cell array structure such that it is now organized in the order of cell array B {48×1} first; second level cell array C {2×1} and lastly a third level cell array of A {691×1}.
Is there a way to take the original cell array and use a specific function (such as reshape) to get my desired new nested cell array from my current nested cell array?
have: A {691×1} –> B{48×1} –> C{2×1}
want: B{48×1} –> C{2×1} –> A {691×1}
Thanks! Hello, I have a nested cell array that has been built up such that the first level cell array A is {691×1}; within each cell in A, there is a second level cell array B of {48×1}; lastly within each cell in B there is a third level nested cell array C of {2×1}.
I want to reshape the nested cell array structure such that it is now organized in the order of cell array B {48×1} first; second level cell array C {2×1} and lastly a third level cell array of A {691×1}.
Is there a way to take the original cell array and use a specific function (such as reshape) to get my desired new nested cell array from my current nested cell array?
have: A {691×1} –> B{48×1} –> C{2×1}
want: B{48×1} –> C{2×1} –> A {691×1}
Thanks! nested cell array, reshape cell array MATLAB Answers — New Questions
Error in reflectarray_gui_v2 (line 42) gui_mainfcn(gui_State, varargin{:});
function varargout = reflectarray_gui_v2(varargin)
% REFLECTARRAY_GUI_V2 MATLAB code for reflectarray_gui_v2.fig
% REFLECTARRAY_GUI_V2, by itself, creates a new REFLECTARRAY_GUI_V2 or raises the existing
% singleton*.
%
% H = REFLECTARRAY_GUI_V2 returns the handle to a new REFLECTARRAY_GUI_V2 or the handle to
% the existing singleton*.
%
% REFLECTARRAY_GUI_V2(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in REFLECTARRAY_GUI_V2.M with the given input arguments.
%
% REFLECTARRAY_GUI_V2(‘Property’,’Value’,…) creates a new REFLECTARRAY_GUI_V2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before reflectarray_gui_v2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to reflectarray_gui_v2_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 reflectarray_gui_v2
% Last Modified by GUIDE v2.5 11-Dec-2019 22:58:28
% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @reflectarray_gui_v2_OpeningFcn, …
‘gui_OutputFcn’, @reflectarray_gui_v2_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 reflectarray_gui_v2 is made visible.
function reflectarray_gui_v2_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 reflectarray_gui_v2 (see VARARGIN)
% Choose default command line output for reflectarray_gui_v2
handles.output = hObject;
axes(handles.axes1)
matlabImage = imread(‘D:S Mdrive-download-20240802T134608Z-001coord.jpg’);
image(matlabImage)
axis off
axis image
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes reflectarray_gui_v2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = reflectarray_gui_v2_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
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
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
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text
% str2double(get(hObject,’String’)) returns contents of edit7 as a double
% — Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,’String’)) returns contents of edit6 as a double
% — Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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)
handles = guidata(hObject);
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
% phas_lin_map=m_phase_deg*m+n;
if m_phase_deg > phas_u(1,1)
phas_lin_map = phas_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = phas_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
axes(handles.axes2)
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
% — Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
CstDefaultUnits(mws)
fmin=2.2;
fmax=2.6;
CstDefineFrequencyRange(mws,fmin,fmax)
CstMeshInitiator(mws)
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
CstDefineOpenBoundary(mws,minfrequency,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
XminSpace = 0;
XmaxSpace = 0;
YminSpace = 0;
YmaxSpace = 0;
ZminSpace = 0;
ZmaxSpace = 0;
CstDefineBackroundMaterial(mws,XminSpace,XmaxSpace,YminSpace,YmaxSpace,ZminSpace,ZmaxSpace)
CstCopperAnnealedLossy(mws)
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
count=1;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
if m_phase_deg > phas_u(1,1)
phas_lin_map = dim_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = dim_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
%CST
Name=num2str(count);
component=’reflectarray’;
count=count+1;
material=’Copper (annealed)’;
Xrange = [-phas_lin_map/2+xi phas_lin_map/2+xi];
Yrange = [-phas_lin_map/2+yi phas_lin_map/2+yi];
Zrange = [0 0.1];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
guidata(hObject, handles);
% — Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
[file,path] = uigetfile(‘*.txt’);
filename = [path file];
delimiter = ‘ ‘;
formatSpec = ‘%f%f%[^nr]’;
fileID = fopen(filename,’r’);
dataArray = textscan(fileID, formatSpec, ‘Delimiter’, delimiter, ‘MultipleDelimsAsOne’, true, ‘TextType’, ‘string’, ‘ReturnOnError’, false);
fclose(fileID);
handles.data = [dataArray{1:end-1}];
clearvars filename delimiter formatSpec fileID dataArray ans;
guidata(hObject, handles);
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit12 as text
% str2double(get(hObject,’String’)) returns contents of edit12 as a double
% — Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit13_Callback(hObject, eventdata, handles)
% hObject handle to edit13 (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 edit13 as text
% str2double(get(hObject,’String’)) returns contents of edit13 as a double
% — Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (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’);
endfunction varargout = reflectarray_gui_v2(varargin)
% REFLECTARRAY_GUI_V2 MATLAB code for reflectarray_gui_v2.fig
% REFLECTARRAY_GUI_V2, by itself, creates a new REFLECTARRAY_GUI_V2 or raises the existing
% singleton*.
%
% H = REFLECTARRAY_GUI_V2 returns the handle to a new REFLECTARRAY_GUI_V2 or the handle to
% the existing singleton*.
%
% REFLECTARRAY_GUI_V2(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in REFLECTARRAY_GUI_V2.M with the given input arguments.
%
% REFLECTARRAY_GUI_V2(‘Property’,’Value’,…) creates a new REFLECTARRAY_GUI_V2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before reflectarray_gui_v2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to reflectarray_gui_v2_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 reflectarray_gui_v2
% Last Modified by GUIDE v2.5 11-Dec-2019 22:58:28
% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @reflectarray_gui_v2_OpeningFcn, …
‘gui_OutputFcn’, @reflectarray_gui_v2_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 reflectarray_gui_v2 is made visible.
function reflectarray_gui_v2_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 reflectarray_gui_v2 (see VARARGIN)
% Choose default command line output for reflectarray_gui_v2
handles.output = hObject;
axes(handles.axes1)
matlabImage = imread(‘D:S Mdrive-download-20240802T134608Z-001coord.jpg’);
image(matlabImage)
axis off
axis image
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes reflectarray_gui_v2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = reflectarray_gui_v2_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
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
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
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text
% str2double(get(hObject,’String’)) returns contents of edit7 as a double
% — Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,’String’)) returns contents of edit6 as a double
% — Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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)
handles = guidata(hObject);
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
% phas_lin_map=m_phase_deg*m+n;
if m_phase_deg > phas_u(1,1)
phas_lin_map = phas_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = phas_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
axes(handles.axes2)
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
% — Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
CstDefaultUnits(mws)
fmin=2.2;
fmax=2.6;
CstDefineFrequencyRange(mws,fmin,fmax)
CstMeshInitiator(mws)
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
CstDefineOpenBoundary(mws,minfrequency,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
XminSpace = 0;
XmaxSpace = 0;
YminSpace = 0;
YmaxSpace = 0;
ZminSpace = 0;
ZmaxSpace = 0;
CstDefineBackroundMaterial(mws,XminSpace,XmaxSpace,YminSpace,YmaxSpace,ZminSpace,ZmaxSpace)
CstCopperAnnealedLossy(mws)
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
count=1;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
if m_phase_deg > phas_u(1,1)
phas_lin_map = dim_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = dim_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
%CST
Name=num2str(count);
component=’reflectarray’;
count=count+1;
material=’Copper (annealed)’;
Xrange = [-phas_lin_map/2+xi phas_lin_map/2+xi];
Yrange = [-phas_lin_map/2+yi phas_lin_map/2+yi];
Zrange = [0 0.1];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
guidata(hObject, handles);
% — Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
[file,path] = uigetfile(‘*.txt’);
filename = [path file];
delimiter = ‘ ‘;
formatSpec = ‘%f%f%[^nr]’;
fileID = fopen(filename,’r’);
dataArray = textscan(fileID, formatSpec, ‘Delimiter’, delimiter, ‘MultipleDelimsAsOne’, true, ‘TextType’, ‘string’, ‘ReturnOnError’, false);
fclose(fileID);
handles.data = [dataArray{1:end-1}];
clearvars filename delimiter formatSpec fileID dataArray ans;
guidata(hObject, handles);
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit12 as text
% str2double(get(hObject,’String’)) returns contents of edit12 as a double
% — Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit13_Callback(hObject, eventdata, handles)
% hObject handle to edit13 (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 edit13 as text
% str2double(get(hObject,’String’)) returns contents of edit13 as a double
% — Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (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 varargout = reflectarray_gui_v2(varargin)
% REFLECTARRAY_GUI_V2 MATLAB code for reflectarray_gui_v2.fig
% REFLECTARRAY_GUI_V2, by itself, creates a new REFLECTARRAY_GUI_V2 or raises the existing
% singleton*.
%
% H = REFLECTARRAY_GUI_V2 returns the handle to a new REFLECTARRAY_GUI_V2 or the handle to
% the existing singleton*.
%
% REFLECTARRAY_GUI_V2(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in REFLECTARRAY_GUI_V2.M with the given input arguments.
%
% REFLECTARRAY_GUI_V2(‘Property’,’Value’,…) creates a new REFLECTARRAY_GUI_V2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before reflectarray_gui_v2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to reflectarray_gui_v2_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 reflectarray_gui_v2
% Last Modified by GUIDE v2.5 11-Dec-2019 22:58:28
% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @reflectarray_gui_v2_OpeningFcn, …
‘gui_OutputFcn’, @reflectarray_gui_v2_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 reflectarray_gui_v2 is made visible.
function reflectarray_gui_v2_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 reflectarray_gui_v2 (see VARARGIN)
% Choose default command line output for reflectarray_gui_v2
handles.output = hObject;
axes(handles.axes1)
matlabImage = imread(‘D:S Mdrive-download-20240802T134608Z-001coord.jpg’);
image(matlabImage)
axis off
axis image
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes reflectarray_gui_v2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = reflectarray_gui_v2_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
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
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
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text
% str2double(get(hObject,’String’)) returns contents of edit7 as a double
% — Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,’String’)) returns contents of edit6 as a double
% — Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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)
handles = guidata(hObject);
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
% phas_lin_map=m_phase_deg*m+n;
if m_phase_deg > phas_u(1,1)
phas_lin_map = phas_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = phas_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
axes(handles.axes2)
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
% — Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
CstDefaultUnits(mws)
fmin=2.2;
fmax=2.6;
CstDefineFrequencyRange(mws,fmin,fmax)
CstMeshInitiator(mws)
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
CstDefineOpenBoundary(mws,minfrequency,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
XminSpace = 0;
XmaxSpace = 0;
YminSpace = 0;
YmaxSpace = 0;
ZminSpace = 0;
ZmaxSpace = 0;
CstDefineBackroundMaterial(mws,XminSpace,XmaxSpace,YminSpace,YmaxSpace,ZminSpace,ZmaxSpace)
CstCopperAnnealedLossy(mws)
freq = str2double(get(handles.edit2,’string’))*10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
phas_u=data(:,1)’;
dim_u=data(:,2)’;
count=1;
the_dir = str2double(get(handles.edit6,’string’));
phi_dir = str2double(get(handles.edit7,’string’));
pha_zer = str2double(get(handles.edit13,’string’));
x_cor = str2double(get(handles.edit3,’string’));
y_cor = str2double(get(handles.edit4,’string’));
z_cor = str2double(get(handles.edit5,’string’));
rad = str2double(get(handles.edit1,’string’));
uedim = str2double(get(handles.edit12,’string’));
for xi=-rad/2+mod(rad/2,uedim):uedim:rad/2
for yi=-rad/2+mod(rad/2,uedim):uedim:rad/2
if sqrt(xi^2+yi^2)<rad/2
R = sqrt((x_cor-xi)^2+(y_cor-yi)^2+z_cor^2);
phase(ix,iy)=k*(R-sind(the_dir)*(xi*cosd(phi_dir)+yi*sind(phi_dir)))+pha_zer;
m_phase=mod(phase(ix,iy),2*pi);
m_phase_deg=m_phase*180/pi-180;
if m_phase_deg > phas_u(1,1)
phas_lin_map = dim_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = dim_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1)+1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
%CST
Name=num2str(count);
component=’reflectarray’;
count=count+1;
material=’Copper (annealed)’;
Xrange = [-phas_lin_map/2+xi phas_lin_map/2+xi];
Yrange = [-phas_lin_map/2+yi phas_lin_map/2+yi];
Zrange = [0 0.1];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
else
phase(ix,iy)=0;
end
iy=iy+1;
end
ix=ix+1;
iy=1;
end
guidata(hObject, handles);
% — Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
[file,path] = uigetfile(‘*.txt’);
filename = [path file];
delimiter = ‘ ‘;
formatSpec = ‘%f%f%[^nr]’;
fileID = fopen(filename,’r’);
dataArray = textscan(fileID, formatSpec, ‘Delimiter’, delimiter, ‘MultipleDelimsAsOne’, true, ‘TextType’, ‘string’, ‘ReturnOnError’, false);
fclose(fileID);
handles.data = [dataArray{1:end-1}];
clearvars filename delimiter formatSpec fileID dataArray ans;
guidata(hObject, handles);
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit12 as text
% str2double(get(hObject,’String’)) returns contents of edit12 as a double
% — Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit13_Callback(hObject, eventdata, handles)
% hObject handle to edit13 (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 edit13 as text
% str2double(get(hObject,’String’)) returns contents of edit13 as a double
% — Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (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 error in reflectarray_gui_v2 (line 42) gui_mai MATLAB Answers — New Questions
Calculate normals from nodes which form a 3D curve
I have a composed cell:
in the first column: the P nodes;
in the second column: the circular geometries
in the third through fifth columns: the components a,b,c of the normal N of the circular geometry
Having other P nodes (see matrix ‘coord’) how can I calculate, for those nodes, the new components of the normal (a,b,c)?
load(‘test_p.mat’)
figure(‘units’,’normalized’,’outerposition’,[0 0 1 1]);
plot3(coord(:,1),coord(:,2),coord(:,3),’k.’,’Markersize’,5);
hold on
for t = 1:height(circle)
plot3(circle{t,1}(:,1),circle{t,1}(:,2),circle{t,1}(:,3),’k.’,’Markersize’,20);
patch(circle{t,2}(:,1),circle{t,2}(:,2),circle{t,2}(:,3),’k’,’FaceAlpha’,0.5);
end
hold off
axis equalI have a composed cell:
in the first column: the P nodes;
in the second column: the circular geometries
in the third through fifth columns: the components a,b,c of the normal N of the circular geometry
Having other P nodes (see matrix ‘coord’) how can I calculate, for those nodes, the new components of the normal (a,b,c)?
load(‘test_p.mat’)
figure(‘units’,’normalized’,’outerposition’,[0 0 1 1]);
plot3(coord(:,1),coord(:,2),coord(:,3),’k.’,’Markersize’,5);
hold on
for t = 1:height(circle)
plot3(circle{t,1}(:,1),circle{t,1}(:,2),circle{t,1}(:,3),’k.’,’Markersize’,20);
patch(circle{t,2}(:,1),circle{t,2}(:,2),circle{t,2}(:,3),’k’,’FaceAlpha’,0.5);
end
hold off
axis equal I have a composed cell:
in the first column: the P nodes;
in the second column: the circular geometries
in the third through fifth columns: the components a,b,c of the normal N of the circular geometry
Having other P nodes (see matrix ‘coord’) how can I calculate, for those nodes, the new components of the normal (a,b,c)?
load(‘test_p.mat’)
figure(‘units’,’normalized’,’outerposition’,[0 0 1 1]);
plot3(coord(:,1),coord(:,2),coord(:,3),’k.’,’Markersize’,5);
hold on
for t = 1:height(circle)
plot3(circle{t,1}(:,1),circle{t,1}(:,2),circle{t,1}(:,3),’k.’,’Markersize’,20);
patch(circle{t,2}(:,1),circle{t,2}(:,2),circle{t,2}(:,3),’k’,’FaceAlpha’,0.5);
end
hold off
axis equal normal, normals, 3d, 3d plots MATLAB Answers — New Questions
Parameter Estimation for a System of Differential Equations
Hello.
Ok, so I’m new to matlab and I’ve got a question regarding parameter estimation for a kinetic model.
I have 4 different reactants and their concentrations are c1, c2, c3 and c4. I also have 4 differential equations, each one related to a concentration (c1, c2, c3 and c4, respectively -see below-) and experimental data for all these concentrations on 12 different times plus the initial condition. The k’s are the rate coefficients. I want to solve this system of ODE’s using ode45 and then use the output to compute the experimental data minus the observed data and use these results to estimate the values of k’s using lsqnonlin, but apparently I can’t solve these ODE’s without numerical values for k -which is what I want to know-. Any help on how to set up the command to solve this?
function dcdt=batch(t,c,k)
dcdt=zeros(4,1);
dcdt(1)=-k(1)*c(1)-k(2)*c(1);
dcdt(2)= k(1)*c(1)+k(4)*c(3)-k(3)*c(2)-k(5)*c(2);
dcdt(3)= k(2)*c(1)+k(3)*c(2)-k(4)*c(3)+k(6)*c(4);
dcdt(4)= k(5)*c(2)-k(6)*c(4);
end
Data:
t c1 c2 c3 c4
0 1 0 0 0
0.1 0.902 0.06997 0.02463 0.00218
0.2 0.8072 0.1353 0.0482 0.008192
0.4 0.6757 0.2123 0.0864 0.0289
0.6 0.5569 0.2789 0.1063 0.06233
0.8 0.4297 0.3292 0.1476 0.09756
1 0.3774 0.3457 0.1485 0.1255
1.5 0.2149 0.3486 0.1821 0.2526
2 0.141 0.3254 0.194 0.3401
3 0.04921 0.2445 0.1742 0.5277
4 0.0178 0.1728 0.1732 0.6323
5 0.006431 0.1091 0.1137 0.7702
6 0.002595 0.08301 0.08224 0.835
Thanks in advance!Hello.
Ok, so I’m new to matlab and I’ve got a question regarding parameter estimation for a kinetic model.
I have 4 different reactants and their concentrations are c1, c2, c3 and c4. I also have 4 differential equations, each one related to a concentration (c1, c2, c3 and c4, respectively -see below-) and experimental data for all these concentrations on 12 different times plus the initial condition. The k’s are the rate coefficients. I want to solve this system of ODE’s using ode45 and then use the output to compute the experimental data minus the observed data and use these results to estimate the values of k’s using lsqnonlin, but apparently I can’t solve these ODE’s without numerical values for k -which is what I want to know-. Any help on how to set up the command to solve this?
function dcdt=batch(t,c,k)
dcdt=zeros(4,1);
dcdt(1)=-k(1)*c(1)-k(2)*c(1);
dcdt(2)= k(1)*c(1)+k(4)*c(3)-k(3)*c(2)-k(5)*c(2);
dcdt(3)= k(2)*c(1)+k(3)*c(2)-k(4)*c(3)+k(6)*c(4);
dcdt(4)= k(5)*c(2)-k(6)*c(4);
end
Data:
t c1 c2 c3 c4
0 1 0 0 0
0.1 0.902 0.06997 0.02463 0.00218
0.2 0.8072 0.1353 0.0482 0.008192
0.4 0.6757 0.2123 0.0864 0.0289
0.6 0.5569 0.2789 0.1063 0.06233
0.8 0.4297 0.3292 0.1476 0.09756
1 0.3774 0.3457 0.1485 0.1255
1.5 0.2149 0.3486 0.1821 0.2526
2 0.141 0.3254 0.194 0.3401
3 0.04921 0.2445 0.1742 0.5277
4 0.0178 0.1728 0.1732 0.6323
5 0.006431 0.1091 0.1137 0.7702
6 0.002595 0.08301 0.08224 0.835
Thanks in advance! Hello.
Ok, so I’m new to matlab and I’ve got a question regarding parameter estimation for a kinetic model.
I have 4 different reactants and their concentrations are c1, c2, c3 and c4. I also have 4 differential equations, each one related to a concentration (c1, c2, c3 and c4, respectively -see below-) and experimental data for all these concentrations on 12 different times plus the initial condition. The k’s are the rate coefficients. I want to solve this system of ODE’s using ode45 and then use the output to compute the experimental data minus the observed data and use these results to estimate the values of k’s using lsqnonlin, but apparently I can’t solve these ODE’s without numerical values for k -which is what I want to know-. Any help on how to set up the command to solve this?
function dcdt=batch(t,c,k)
dcdt=zeros(4,1);
dcdt(1)=-k(1)*c(1)-k(2)*c(1);
dcdt(2)= k(1)*c(1)+k(4)*c(3)-k(3)*c(2)-k(5)*c(2);
dcdt(3)= k(2)*c(1)+k(3)*c(2)-k(4)*c(3)+k(6)*c(4);
dcdt(4)= k(5)*c(2)-k(6)*c(4);
end
Data:
t c1 c2 c3 c4
0 1 0 0 0
0.1 0.902 0.06997 0.02463 0.00218
0.2 0.8072 0.1353 0.0482 0.008192
0.4 0.6757 0.2123 0.0864 0.0289
0.6 0.5569 0.2789 0.1063 0.06233
0.8 0.4297 0.3292 0.1476 0.09756
1 0.3774 0.3457 0.1485 0.1255
1.5 0.2149 0.3486 0.1821 0.2526
2 0.141 0.3254 0.194 0.3401
3 0.04921 0.2445 0.1742 0.5277
4 0.0178 0.1728 0.1732 0.6323
5 0.006431 0.1091 0.1137 0.7702
6 0.002595 0.08301 0.08224 0.835
Thanks in advance! parameter estimation, system of ode’s MATLAB Answers — New Questions
How do I plot an empty circle with no values in the middle of meshgrid plot3
Hi everyone.
Bascially I am tracking the depth of a surface using grids. x,y coordinates and z for depth. To fill the voids in between grids, I am using meshgrid with natural interpolation. However I have placed a circular piece in the middle of the grid hence on a plot3 it is supposed to be a white circular figue. How do I make sure this is drawn correctly because the image I attached does not look correct. Also how do I make sure that the meshgrid interpolates around the shape of the circle in the middle? This the code I have currently.
x = data(:,1); y = data(:,2); z = data(:,3)
x = table2array(x); y = table2array(y); z = table2array(z)
xlin = linspace(min(x), max(x), 100);
ylin = linspace(min(y), max(y), 100);
[X,Y] = meshgrid(xlin, ylin);
Z = griddata(x,y,z,X,Y,’natural’);
% Z = griddata(x,y,z,X,Y,’cubic’);
% Z = griddata(x,y,z,X,Y,’v4′);
mesh(X,Y,Z)
axis tight; hold on
plot3(x,y,z,’.’,’MarkerSize’,15)Hi everyone.
Bascially I am tracking the depth of a surface using grids. x,y coordinates and z for depth. To fill the voids in between grids, I am using meshgrid with natural interpolation. However I have placed a circular piece in the middle of the grid hence on a plot3 it is supposed to be a white circular figue. How do I make sure this is drawn correctly because the image I attached does not look correct. Also how do I make sure that the meshgrid interpolates around the shape of the circle in the middle? This the code I have currently.
x = data(:,1); y = data(:,2); z = data(:,3)
x = table2array(x); y = table2array(y); z = table2array(z)
xlin = linspace(min(x), max(x), 100);
ylin = linspace(min(y), max(y), 100);
[X,Y] = meshgrid(xlin, ylin);
Z = griddata(x,y,z,X,Y,’natural’);
% Z = griddata(x,y,z,X,Y,’cubic’);
% Z = griddata(x,y,z,X,Y,’v4′);
mesh(X,Y,Z)
axis tight; hold on
plot3(x,y,z,’.’,’MarkerSize’,15) Hi everyone.
Bascially I am tracking the depth of a surface using grids. x,y coordinates and z for depth. To fill the voids in between grids, I am using meshgrid with natural interpolation. However I have placed a circular piece in the middle of the grid hence on a plot3 it is supposed to be a white circular figue. How do I make sure this is drawn correctly because the image I attached does not look correct. Also how do I make sure that the meshgrid interpolates around the shape of the circle in the middle? This the code I have currently.
x = data(:,1); y = data(:,2); z = data(:,3)
x = table2array(x); y = table2array(y); z = table2array(z)
xlin = linspace(min(x), max(x), 100);
ylin = linspace(min(y), max(y), 100);
[X,Y] = meshgrid(xlin, ylin);
Z = griddata(x,y,z,X,Y,’natural’);
% Z = griddata(x,y,z,X,Y,’cubic’);
% Z = griddata(x,y,z,X,Y,’v4′);
mesh(X,Y,Z)
axis tight; hold on
plot3(x,y,z,’.’,’MarkerSize’,15) meshgrid, plot3 MATLAB Answers — New Questions
Help understanding how function handle is used
So I had an extremely helpful replier in an earlier question given me an equation for an interpolation function (I didn’t know about the floor and ceil function which would’ve answered my question and given me the opportunity to try writting the interpolation function myself, but I’m not going to look a gift horse in the mouth)
function fitness = interFt(Ft, x, j, k, t)
% Find the floor and ceiling for j and k
j_floor = floor(j);
j_ceil = ceil(j);
k_floor = floor(k);
k_ceil = ceil(k);
% Calculate probabilities based on the distance from the actual values
p_j_floor = j_ceil – j;
p_j_ceil = j – j_floor;
p_k_floor = k_ceil – k;
p_k_ceil = k – k_floor;
% Calculate the weighted fitness for each combination
fitness = 0;
fitness = fitness + p_j_floor * p_k_floor * Ft(x, j_floor, k_floor, t);
fitness = fitness + p_j_floor * p_k_ceil * Ft(x, j_floor, k_ceil, t);
fitness = fitness + p_j_ceil * p_k_floor * Ft(x, j_ceil, k_floor, t);
fitness = fitness + p_j_ceil * p_k_ceil * Ft(x, j_ceil, k_ceil, t);
end
They also gave me an example of how to use the function, but they used a function handle and i’m not sure how it’s being used
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
% here is a snipet of my code that I’m using with one of the
% examples of how I’m using the InterFt function; it’s set up
% exactly how the replier showed
state1 = interFt(@(x,j,k,t) Ft(x,j,k,t), xp(i),zp(j),yy(k),tt+1);
end
end
end
end
Why is Ft not included in the @()?
Why is it that when I change the x’s to i’s it messes things up (while also changing the x to an i in the written function)?
I know you’re not supposed to include the entire code, but let me know if that’s needed to see what I mean
Here is the link to the original question: https://www.mathworks.com/matlabcentral/answers/2119211-creating-a-function-for-linear-interpolation-based-on-two-changing-states?s_tid=srchtitle
[[I have a lot of code that I think has something wrong with it, and I think has to do with the states, but I’m not sure how I need to "fix" it]]So I had an extremely helpful replier in an earlier question given me an equation for an interpolation function (I didn’t know about the floor and ceil function which would’ve answered my question and given me the opportunity to try writting the interpolation function myself, but I’m not going to look a gift horse in the mouth)
function fitness = interFt(Ft, x, j, k, t)
% Find the floor and ceiling for j and k
j_floor = floor(j);
j_ceil = ceil(j);
k_floor = floor(k);
k_ceil = ceil(k);
% Calculate probabilities based on the distance from the actual values
p_j_floor = j_ceil – j;
p_j_ceil = j – j_floor;
p_k_floor = k_ceil – k;
p_k_ceil = k – k_floor;
% Calculate the weighted fitness for each combination
fitness = 0;
fitness = fitness + p_j_floor * p_k_floor * Ft(x, j_floor, k_floor, t);
fitness = fitness + p_j_floor * p_k_ceil * Ft(x, j_floor, k_ceil, t);
fitness = fitness + p_j_ceil * p_k_floor * Ft(x, j_ceil, k_floor, t);
fitness = fitness + p_j_ceil * p_k_ceil * Ft(x, j_ceil, k_ceil, t);
end
They also gave me an example of how to use the function, but they used a function handle and i’m not sure how it’s being used
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
% here is a snipet of my code that I’m using with one of the
% examples of how I’m using the InterFt function; it’s set up
% exactly how the replier showed
state1 = interFt(@(x,j,k,t) Ft(x,j,k,t), xp(i),zp(j),yy(k),tt+1);
end
end
end
end
Why is Ft not included in the @()?
Why is it that when I change the x’s to i’s it messes things up (while also changing the x to an i in the written function)?
I know you’re not supposed to include the entire code, but let me know if that’s needed to see what I mean
Here is the link to the original question: https://www.mathworks.com/matlabcentral/answers/2119211-creating-a-function-for-linear-interpolation-based-on-two-changing-states?s_tid=srchtitle
[[I have a lot of code that I think has something wrong with it, and I think has to do with the states, but I’m not sure how I need to "fix" it]] So I had an extremely helpful replier in an earlier question given me an equation for an interpolation function (I didn’t know about the floor and ceil function which would’ve answered my question and given me the opportunity to try writting the interpolation function myself, but I’m not going to look a gift horse in the mouth)
function fitness = interFt(Ft, x, j, k, t)
% Find the floor and ceiling for j and k
j_floor = floor(j);
j_ceil = ceil(j);
k_floor = floor(k);
k_ceil = ceil(k);
% Calculate probabilities based on the distance from the actual values
p_j_floor = j_ceil – j;
p_j_ceil = j – j_floor;
p_k_floor = k_ceil – k;
p_k_ceil = k – k_floor;
% Calculate the weighted fitness for each combination
fitness = 0;
fitness = fitness + p_j_floor * p_k_floor * Ft(x, j_floor, k_floor, t);
fitness = fitness + p_j_floor * p_k_ceil * Ft(x, j_floor, k_ceil, t);
fitness = fitness + p_j_ceil * p_k_floor * Ft(x, j_ceil, k_floor, t);
fitness = fitness + p_j_ceil * p_k_ceil * Ft(x, j_ceil, k_ceil, t);
end
They also gave me an example of how to use the function, but they used a function handle and i’m not sure how it’s being used
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
% here is a snipet of my code that I’m using with one of the
% examples of how I’m using the InterFt function; it’s set up
% exactly how the replier showed
state1 = interFt(@(x,j,k,t) Ft(x,j,k,t), xp(i),zp(j),yy(k),tt+1);
end
end
end
end
Why is Ft not included in the @()?
Why is it that when I change the x’s to i’s it messes things up (while also changing the x to an i in the written function)?
I know you’re not supposed to include the entire code, but let me know if that’s needed to see what I mean
Here is the link to the original question: https://www.mathworks.com/matlabcentral/answers/2119211-creating-a-function-for-linear-interpolation-based-on-two-changing-states?s_tid=srchtitle
[[I have a lot of code that I think has something wrong with it, and I think has to do with the states, but I’m not sure how I need to "fix" it]] interpolation, function handle MATLAB Answers — New Questions
How to generate Generic VHDL from simulink for sysgen model?
I have used xilinx basic blocks to design a model. I wanted to generate generic VHDL without xilinx specific references. Eventhough i have choosen Behavioural HDL for implementation generated vhdl consist of xilinx specific DFlip-Flop and SRLUTs. Kindly let me know if there is a way? if the option is not being applied then how can we write a matlab sript to set automatically without doing it manually?I have used xilinx basic blocks to design a model. I wanted to generate generic VHDL without xilinx specific references. Eventhough i have choosen Behavioural HDL for implementation generated vhdl consist of xilinx specific DFlip-Flop and SRLUTs. Kindly let me know if there is a way? if the option is not being applied then how can we write a matlab sript to set automatically without doing it manually? I have used xilinx basic blocks to design a model. I wanted to generate generic VHDL without xilinx specific references. Eventhough i have choosen Behavioural HDL for implementation generated vhdl consist of xilinx specific DFlip-Flop and SRLUTs. Kindly let me know if there is a way? if the option is not being applied then how can we write a matlab sript to set automatically without doing it manually? systemgenerator, vhdl, matlab, xilinx, simulink MATLAB Answers — New Questions
How do I solve this error?: Matrix out of range for deletion
Can someone help me to figure out why I am out of range for deletion with this? This code was first used with data that had multiple values in the matrix (i.e. "carbclay" was a matrix with 4 values), but now I’m only doing it with one value, so maybe that’s why it’s not working? I have gotten a lot of help with this so I don’t quite understand it fully, forgive my lack of knowledge when it comes to calling things the right name, hope someone can understand what’s wrong:( The goal of the code is to be able to leave off legend entries if any of the data that I want to plot is missing from my table.
carbclay=[rocktypes(1)]; missingdata1=[];
np = 0;
hp = [];
legtxt = {};
i = find(string(TAllData.gen_rock_type)==carbclay);
if any([sum(isnan(TAllData.a_b(i)))==length(i),sum(isnan(TAllData.temp(i)))==length(i)])
missingdata1=[missingdata1,i];
else hp(end+1) = scatter(TAllData.temp(i),TAllData.a_b(i),120,c1,’filled’,’o’,’MarkerFaceAlpha’,0.7);
legtxt{end+1} = carbclay{1};
end
carbclay(missingdata1)=”; %The error happens here for some reason, and then the legend does not show up
legend(hp,legtxt,’Location’,’northeastoutside’);
Error Message:
Matrix index is out of range for deletion.
Error in ScriptForPlots_RFD (line 1507)
carbclay(missingdata1)=”;Can someone help me to figure out why I am out of range for deletion with this? This code was first used with data that had multiple values in the matrix (i.e. "carbclay" was a matrix with 4 values), but now I’m only doing it with one value, so maybe that’s why it’s not working? I have gotten a lot of help with this so I don’t quite understand it fully, forgive my lack of knowledge when it comes to calling things the right name, hope someone can understand what’s wrong:( The goal of the code is to be able to leave off legend entries if any of the data that I want to plot is missing from my table.
carbclay=[rocktypes(1)]; missingdata1=[];
np = 0;
hp = [];
legtxt = {};
i = find(string(TAllData.gen_rock_type)==carbclay);
if any([sum(isnan(TAllData.a_b(i)))==length(i),sum(isnan(TAllData.temp(i)))==length(i)])
missingdata1=[missingdata1,i];
else hp(end+1) = scatter(TAllData.temp(i),TAllData.a_b(i),120,c1,’filled’,’o’,’MarkerFaceAlpha’,0.7);
legtxt{end+1} = carbclay{1};
end
carbclay(missingdata1)=”; %The error happens here for some reason, and then the legend does not show up
legend(hp,legtxt,’Location’,’northeastoutside’);
Error Message:
Matrix index is out of range for deletion.
Error in ScriptForPlots_RFD (line 1507)
carbclay(missingdata1)=”; Can someone help me to figure out why I am out of range for deletion with this? This code was first used with data that had multiple values in the matrix (i.e. "carbclay" was a matrix with 4 values), but now I’m only doing it with one value, so maybe that’s why it’s not working? I have gotten a lot of help with this so I don’t quite understand it fully, forgive my lack of knowledge when it comes to calling things the right name, hope someone can understand what’s wrong:( The goal of the code is to be able to leave off legend entries if any of the data that I want to plot is missing from my table.
carbclay=[rocktypes(1)]; missingdata1=[];
np = 0;
hp = [];
legtxt = {};
i = find(string(TAllData.gen_rock_type)==carbclay);
if any([sum(isnan(TAllData.a_b(i)))==length(i),sum(isnan(TAllData.temp(i)))==length(i)])
missingdata1=[missingdata1,i];
else hp(end+1) = scatter(TAllData.temp(i),TAllData.a_b(i),120,c1,’filled’,’o’,’MarkerFaceAlpha’,0.7);
legtxt{end+1} = carbclay{1};
end
carbclay(missingdata1)=”; %The error happens here for some reason, and then the legend does not show up
legend(hp,legtxt,’Location’,’northeastoutside’);
Error Message:
Matrix index is out of range for deletion.
Error in ScriptForPlots_RFD (line 1507)
carbclay(missingdata1)=”; matrix, table, legend MATLAB Answers — New Questions
Seasonal decomposition of a daily time series
I have a time series that contains daily variation from 2015 to 2023. I want to see the trend, seasonal components and unmodelled part. Kindly help. The time series has veen attachedI have a time series that contains daily variation from 2015 to 2023. I want to see the trend, seasonal components and unmodelled part. Kindly help. The time series has veen attached I have a time series that contains daily variation from 2015 to 2023. I want to see the trend, seasonal components and unmodelled part. Kindly help. The time series has veen attached time series analysis, seasonal adjustment, seasonal decomposition MATLAB Answers — New Questions
Please explain the maths behind calculating lateral deviation
Please explain me the maths behind the lateral deviation used in many exmples.
Curvature unit is m-1 and if we multiply by logitudinal velocity (m/s), we get s-1 which is rate of change / frequency. How are we subrating Yaw rate by it?
And how are we getting e1 from u3*u2 + u1?Please explain me the maths behind the lateral deviation used in many exmples.
Curvature unit is m-1 and if we multiply by logitudinal velocity (m/s), we get s-1 which is rate of change / frequency. How are we subrating Yaw rate by it?
And how are we getting e1 from u3*u2 + u1? Please explain me the maths behind the lateral deviation used in many exmples.
Curvature unit is m-1 and if we multiply by logitudinal velocity (m/s), we get s-1 which is rate of change / frequency. How are we subrating Yaw rate by it?
And how are we getting e1 from u3*u2 + u1? model predictive control toolbox, vehicle dynamics, trajectories, path planning MATLAB Answers — New Questions
Invalid expression during a function handle
I am recieving the following error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
This is the line that is causing the error:
Kernel = @x q.*(exp(-jk.*(sqrt(a^2 + (m1 – (x)).^2)))./(4*pi.*((sqrt(a^2 + (m1 – (x)).^2)).^5)))*((1+jk.*(sqrt(a^2 + (m1 – (x)).^2))).*(2*((sqrt(a^2 + (m1 – (x)).^2)).^2)-3.*(a^2))+((k*a.*(sqrt(a^2 + (m1 – (x)).^2))).^2));
The following variables have already been defined prior to this line:
q, jk, m1, k and a. The only variable is x.
I counted the parentheses, checked the multiplication operator, and I am not trying to construct a matrix.
Some background context:
This line is within 2 for loops. When I take off the function handle (@x) and set x = 1, the code runs without any errors. I plan on integrating this Kernel function and pass it to an array. The original equation is q*(exp(-jk*R)/(4*pi*(R^5)))*((1+jk*R)*(2*(R^2)-3*(a^2))+((k*a*R)^2)) but since the variable X is within R, I expanded R at each instance. R = sqrt(a^2 + (m1 – m2)^2)
Thank you guys in advance!I am recieving the following error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
This is the line that is causing the error:
Kernel = @x q.*(exp(-jk.*(sqrt(a^2 + (m1 – (x)).^2)))./(4*pi.*((sqrt(a^2 + (m1 – (x)).^2)).^5)))*((1+jk.*(sqrt(a^2 + (m1 – (x)).^2))).*(2*((sqrt(a^2 + (m1 – (x)).^2)).^2)-3.*(a^2))+((k*a.*(sqrt(a^2 + (m1 – (x)).^2))).^2));
The following variables have already been defined prior to this line:
q, jk, m1, k and a. The only variable is x.
I counted the parentheses, checked the multiplication operator, and I am not trying to construct a matrix.
Some background context:
This line is within 2 for loops. When I take off the function handle (@x) and set x = 1, the code runs without any errors. I plan on integrating this Kernel function and pass it to an array. The original equation is q*(exp(-jk*R)/(4*pi*(R^5)))*((1+jk*R)*(2*(R^2)-3*(a^2))+((k*a*R)^2)) but since the variable X is within R, I expanded R at each instance. R = sqrt(a^2 + (m1 – m2)^2)
Thank you guys in advance! I am recieving the following error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
This is the line that is causing the error:
Kernel = @x q.*(exp(-jk.*(sqrt(a^2 + (m1 – (x)).^2)))./(4*pi.*((sqrt(a^2 + (m1 – (x)).^2)).^5)))*((1+jk.*(sqrt(a^2 + (m1 – (x)).^2))).*(2*((sqrt(a^2 + (m1 – (x)).^2)).^2)-3.*(a^2))+((k*a.*(sqrt(a^2 + (m1 – (x)).^2))).^2));
The following variables have already been defined prior to this line:
q, jk, m1, k and a. The only variable is x.
I counted the parentheses, checked the multiplication operator, and I am not trying to construct a matrix.
Some background context:
This line is within 2 for loops. When I take off the function handle (@x) and set x = 1, the code runs without any errors. I plan on integrating this Kernel function and pass it to an array. The original equation is q*(exp(-jk*R)/(4*pi*(R^5)))*((1+jk*R)*(2*(R^2)-3*(a^2))+((k*a*R)^2)) but since the variable X is within R, I expanded R at each instance. R = sqrt(a^2 + (m1 – m2)^2)
Thank you guys in advance! function, matlab function, integral MATLAB Answers — New Questions
How to iteratively go through a structure?
I have some data from 100 different tests that I ran. There are 2 variables that were swept through for 10 values each, resulting in 100 tests (i.e. variable 1 is A with 10 elements, variable 2 is B with 10 elements, my test data is from all the permutations of A and B). A few timeseries measurements are made for each test. I have my data saved in a structure like:
Data.A1.B1.meas1
Data.A1.B1.meas2
%…
Data.A1.B1.measN
Data.A1.B2.meas1
Data.A1.B2.meas2
%…
Data.A2.B1.meas1
%…
Data.A10.B10.measN
I need to take the mean of the timeseries data for each test. Is there some way to set up a loop such that I can easily iterate through the struct to do this? Some thing like:
for i = 1:10
for j = 1:10
DataMean = mean(Data.A(i).B(j).meas1)
end
end
Is there a more efficient way to structure the data to make this easier?I have some data from 100 different tests that I ran. There are 2 variables that were swept through for 10 values each, resulting in 100 tests (i.e. variable 1 is A with 10 elements, variable 2 is B with 10 elements, my test data is from all the permutations of A and B). A few timeseries measurements are made for each test. I have my data saved in a structure like:
Data.A1.B1.meas1
Data.A1.B1.meas2
%…
Data.A1.B1.measN
Data.A1.B2.meas1
Data.A1.B2.meas2
%…
Data.A2.B1.meas1
%…
Data.A10.B10.measN
I need to take the mean of the timeseries data for each test. Is there some way to set up a loop such that I can easily iterate through the struct to do this? Some thing like:
for i = 1:10
for j = 1:10
DataMean = mean(Data.A(i).B(j).meas1)
end
end
Is there a more efficient way to structure the data to make this easier? I have some data from 100 different tests that I ran. There are 2 variables that were swept through for 10 values each, resulting in 100 tests (i.e. variable 1 is A with 10 elements, variable 2 is B with 10 elements, my test data is from all the permutations of A and B). A few timeseries measurements are made for each test. I have my data saved in a structure like:
Data.A1.B1.meas1
Data.A1.B1.meas2
%…
Data.A1.B1.measN
Data.A1.B2.meas1
Data.A1.B2.meas2
%…
Data.A2.B1.meas1
%…
Data.A10.B10.measN
I need to take the mean of the timeseries data for each test. Is there some way to set up a loop such that I can easily iterate through the struct to do this? Some thing like:
for i = 1:10
for j = 1:10
DataMean = mean(Data.A(i).B(j).meas1)
end
end
Is there a more efficient way to structure the data to make this easier? structures, loops MATLAB Answers — New Questions
Save numbers after text pattern in a vector
Dear all
I have a text file that looks like these:
#——————————————————
# Atomistic spin configuration file for vampire v5+
#——————————————————
# Date: Wed Jul 31 19:19:54 2024
#——————————————————
Time: 1e-15
Field: 0 0 0
Temperature: 0.05
Magnetisation: -0.999883 0.0152572 -0.000478932
#——————————————————
Number of spin files: 1
spins-00000000.data
#——————————————————
I am interested in saving in an array the three numerical values after "Field:". I have tried something like
field_str=regexp(meta_file_read,'(?<=^TField:s+)(S+)s*(S+)s*(S+)’,’match’,’lineanchors’); % T
But the cell seems to be empty.
Any ideas?Dear all
I have a text file that looks like these:
#——————————————————
# Atomistic spin configuration file for vampire v5+
#——————————————————
# Date: Wed Jul 31 19:19:54 2024
#——————————————————
Time: 1e-15
Field: 0 0 0
Temperature: 0.05
Magnetisation: -0.999883 0.0152572 -0.000478932
#——————————————————
Number of spin files: 1
spins-00000000.data
#——————————————————
I am interested in saving in an array the three numerical values after "Field:". I have tried something like
field_str=regexp(meta_file_read,'(?<=^TField:s+)(S+)s*(S+)s*(S+)’,’match’,’lineanchors’); % T
But the cell seems to be empty.
Any ideas? Dear all
I have a text file that looks like these:
#——————————————————
# Atomistic spin configuration file for vampire v5+
#——————————————————
# Date: Wed Jul 31 19:19:54 2024
#——————————————————
Time: 1e-15
Field: 0 0 0
Temperature: 0.05
Magnetisation: -0.999883 0.0152572 -0.000478932
#——————————————————
Number of spin files: 1
spins-00000000.data
#——————————————————
I am interested in saving in an array the three numerical values after "Field:". I have tried something like
field_str=regexp(meta_file_read,'(?<=^TField:s+)(S+)s*(S+)s*(S+)’,’match’,’lineanchors’); % T
But the cell seems to be empty.
Any ideas? text patterns MATLAB Answers — New Questions
how to make subscripts in plot labeling
Hello
I have a plot as shown below. However i wantet to make the x and y labeling in subscript
forexample in the x and y label 1 next to K should be subscripted
Thank you for your helpHello
I have a plot as shown below. However i wantet to make the x and y labeling in subscript
forexample in the x and y label 1 next to K should be subscripted
Thank you for your help Hello
I have a plot as shown below. However i wantet to make the x and y labeling in subscript
forexample in the x and y label 1 next to K should be subscripted
Thank you for your help labeling MATLAB Answers — New Questions
Standalone App will not install without internet
I am trying to run the installer for a standalone app that was compiled with the option to download runtime engine from web. However what I would like to do is have the runtime engine installed on the target computer in advance. This computer is not connected to the internet. When I try to run the app installer on this computer, I get an error since the computer is not connected to the internet. It does not even try to check if the runtime engine is already installed on the computer.
I don’t want to compile the installer that contains the runtime engine, since that is a very large file and takes a long time to compile each time. Is there a way to configure the app installer so that
1) I don’t need to include the entire runtime engine with it
2) The target computer does not need to be connected to the internet during installation?I am trying to run the installer for a standalone app that was compiled with the option to download runtime engine from web. However what I would like to do is have the runtime engine installed on the target computer in advance. This computer is not connected to the internet. When I try to run the app installer on this computer, I get an error since the computer is not connected to the internet. It does not even try to check if the runtime engine is already installed on the computer.
I don’t want to compile the installer that contains the runtime engine, since that is a very large file and takes a long time to compile each time. Is there a way to configure the app installer so that
1) I don’t need to include the entire runtime engine with it
2) The target computer does not need to be connected to the internet during installation? I am trying to run the installer for a standalone app that was compiled with the option to download runtime engine from web. However what I would like to do is have the runtime engine installed on the target computer in advance. This computer is not connected to the internet. When I try to run the app installer on this computer, I get an error since the computer is not connected to the internet. It does not even try to check if the runtime engine is already installed on the computer.
I don’t want to compile the installer that contains the runtime engine, since that is a very large file and takes a long time to compile each time. Is there a way to configure the app installer so that
1) I don’t need to include the entire runtime engine with it
2) The target computer does not need to be connected to the internet during installation? app designer, compiler MATLAB Answers — New Questions
Showing the error “Variable nDimes has an incorrect value”
For this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
endFor this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
end For this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
end image processing, image segmentation, image analysis MATLAB Answers — New Questions
Why did I get duplicate variables in my workspace after changing their names?
(I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here.(I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here. (I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here. variable-names, duplicates MATLAB Answers — New Questions
Field-Oriented Control of PMSM Using Reinforcement Learning code
Does anyone know where to find that Matlab code for the example presented
Field-Oriented Control of PMSM Using Reinforcement Learning
the is shown below but Matlab does not seem to have this code:
https://www.mathworks.com/help/mcb/gs/foc-of-pmsm-using-reinforcement-learning.htmlDoes anyone know where to find that Matlab code for the example presented
Field-Oriented Control of PMSM Using Reinforcement Learning
the is shown below but Matlab does not seem to have this code:
https://www.mathworks.com/help/mcb/gs/foc-of-pmsm-using-reinforcement-learning.html Does anyone know where to find that Matlab code for the example presented
Field-Oriented Control of PMSM Using Reinforcement Learning
the is shown below but Matlab does not seem to have this code:
https://www.mathworks.com/help/mcb/gs/foc-of-pmsm-using-reinforcement-learning.html @john MATLAB Answers — New Questions
Unrecognized property Value for class Axes?
Hi all,
I have been trying to create a CT scan viewer through Matlab.
It is up and running, however, I am getting the error Unrecognized property Value for class Axes whenever I change and image.
It hightlights these two lines of code for me.
% Add listener to the slider to call a function when its value changes
addlistener(hSlider, ‘Value’, ‘PostSet’, @(src, event) updateImage(src, event, hAxes, dicomImages));
and
% Get the current value of the slider
sliderValue = round(get(hAxes.Parent.Children(2), ‘Value’)); % hAxes.Parent.Children(2) is the slider handle
Would anyone know where I went wrong?Hi all,
I have been trying to create a CT scan viewer through Matlab.
It is up and running, however, I am getting the error Unrecognized property Value for class Axes whenever I change and image.
It hightlights these two lines of code for me.
% Add listener to the slider to call a function when its value changes
addlistener(hSlider, ‘Value’, ‘PostSet’, @(src, event) updateImage(src, event, hAxes, dicomImages));
and
% Get the current value of the slider
sliderValue = round(get(hAxes.Parent.Children(2), ‘Value’)); % hAxes.Parent.Children(2) is the slider handle
Would anyone know where I went wrong? Hi all,
I have been trying to create a CT scan viewer through Matlab.
It is up and running, however, I am getting the error Unrecognized property Value for class Axes whenever I change and image.
It hightlights these two lines of code for me.
% Add listener to the slider to call a function when its value changes
addlistener(hSlider, ‘Value’, ‘PostSet’, @(src, event) updateImage(src, event, hAxes, dicomImages));
and
% Get the current value of the slider
sliderValue = round(get(hAxes.Parent.Children(2), ‘Value’)); % hAxes.Parent.Children(2) is the slider handle
Would anyone know where I went wrong? dicom, slider, matlab gui, image processing MATLAB Answers — New Questions
How do I save each response in an excel file every time I click the submit button?
It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app);It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app); It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app); matlab, excel, table MATLAB Answers — New Questions