Category: Matlab
Category Archives: Matlab
When I use Turkish characters in comments, they turn into question marks when I reopen the file
When I use Turkish characters in comments in MATLAB, they turn into question marks when I reopen the file. How can I solve this issue?
I also encounter this problem when using a directory with turkish characters.
I’m using MATLAB 2023B, operating system is Windows 10.When I use Turkish characters in comments in MATLAB, they turn into question marks when I reopen the file. How can I solve this issue?
I also encounter this problem when using a directory with turkish characters.
I’m using MATLAB 2023B, operating system is Windows 10. When I use Turkish characters in comments in MATLAB, they turn into question marks when I reopen the file. How can I solve this issue?
I also encounter this problem when using a directory with turkish characters.
I’m using MATLAB 2023B, operating system is Windows 10. language, characters, encoding MATLAB Answers — New Questions
how to solve my problem that i write
I write this code and i wanne output that show me like a sinc function like picture that i attached. the other point is about my l value that i defined it, i wanne some random number between 11e-6 till 13e-6, is it true like this that i define?
tnx.
clc;
clear;
close all;
capital_lambda = 20e-6;
% define sellmier equation to obtain refractive index
lambda_sh=0.775e-6; % SH wavelength
nlithium_sh = 2.1784;
lambda_ff=1.55e-6; % FF wavelength
nlithium_ff = 2.1376;
% parameters
capital_lambda = 20e-6;
k_sh=(2*pi/lambda_sh)*nlithium_sh;
k_ff=(2*pi/lambda_ff)*nlithium_ff;
Delta_kk = k_sh-2*k_ff;
%km=2*pi/capital_lambda;
L = 1; % Length;
sigma_l = 2; % sigma_l = l*sigma_avg
N=L/(capital_lambda/2); % number of domains
l=unifrnd(11e-6,13e-6,[1,1000]); %
for i=l
f=exp(-(pi.^2) .* (sigma_l.^2)/2.*(l.^2));
Delta_k=(k_sh-2*k_ff)-pi./l;
E3= f .* (sinc((Delta_k .* L)/2)).^2 + ((1-f)/N);
end
plot(E3)
%plot(abs(fftshift(fft2(E3))))
xlabel(‘(Delta_k * L)/pi’);
ylabel(‘SHG Effiency’);I write this code and i wanne output that show me like a sinc function like picture that i attached. the other point is about my l value that i defined it, i wanne some random number between 11e-6 till 13e-6, is it true like this that i define?
tnx.
clc;
clear;
close all;
capital_lambda = 20e-6;
% define sellmier equation to obtain refractive index
lambda_sh=0.775e-6; % SH wavelength
nlithium_sh = 2.1784;
lambda_ff=1.55e-6; % FF wavelength
nlithium_ff = 2.1376;
% parameters
capital_lambda = 20e-6;
k_sh=(2*pi/lambda_sh)*nlithium_sh;
k_ff=(2*pi/lambda_ff)*nlithium_ff;
Delta_kk = k_sh-2*k_ff;
%km=2*pi/capital_lambda;
L = 1; % Length;
sigma_l = 2; % sigma_l = l*sigma_avg
N=L/(capital_lambda/2); % number of domains
l=unifrnd(11e-6,13e-6,[1,1000]); %
for i=l
f=exp(-(pi.^2) .* (sigma_l.^2)/2.*(l.^2));
Delta_k=(k_sh-2*k_ff)-pi./l;
E3= f .* (sinc((Delta_k .* L)/2)).^2 + ((1-f)/N);
end
plot(E3)
%plot(abs(fftshift(fft2(E3))))
xlabel(‘(Delta_k * L)/pi’);
ylabel(‘SHG Effiency’); I write this code and i wanne output that show me like a sinc function like picture that i attached. the other point is about my l value that i defined it, i wanne some random number between 11e-6 till 13e-6, is it true like this that i define?
tnx.
clc;
clear;
close all;
capital_lambda = 20e-6;
% define sellmier equation to obtain refractive index
lambda_sh=0.775e-6; % SH wavelength
nlithium_sh = 2.1784;
lambda_ff=1.55e-6; % FF wavelength
nlithium_ff = 2.1376;
% parameters
capital_lambda = 20e-6;
k_sh=(2*pi/lambda_sh)*nlithium_sh;
k_ff=(2*pi/lambda_ff)*nlithium_ff;
Delta_kk = k_sh-2*k_ff;
%km=2*pi/capital_lambda;
L = 1; % Length;
sigma_l = 2; % sigma_l = l*sigma_avg
N=L/(capital_lambda/2); % number of domains
l=unifrnd(11e-6,13e-6,[1,1000]); %
for i=l
f=exp(-(pi.^2) .* (sigma_l.^2)/2.*(l.^2));
Delta_k=(k_sh-2*k_ff)-pi./l;
E3= f .* (sinc((Delta_k .* L)/2)).^2 + ((1-f)/N);
end
plot(E3)
%plot(abs(fftshift(fft2(E3))))
xlabel(‘(Delta_k * L)/pi’);
ylabel(‘SHG Effiency’); sinc function, hann window, rectangle, fft, shg effiency MATLAB Answers — New Questions
Setting Maximum Array Size Threshold in Simulink Model for Embedded C Code Generation
Hi,
I am trying to understand how to set maximum size arrays threshold in case of a Simulink model that needs to use Matlab functions that support variable size arrays.
Is "Maximum stack size (bytes)" the proper parameter to set? I am asking this since I have to generate a C code for my model for an embedded application and I need to be sure to set an upper threshold for all the variables inside my model.Hi,
I am trying to understand how to set maximum size arrays threshold in case of a Simulink model that needs to use Matlab functions that support variable size arrays.
Is "Maximum stack size (bytes)" the proper parameter to set? I am asking this since I have to generate a C code for my model for an embedded application and I need to be sure to set an upper threshold for all the variables inside my model. Hi,
I am trying to understand how to set maximum size arrays threshold in case of a Simulink model that needs to use Matlab functions that support variable size arrays.
Is "Maximum stack size (bytes)" the proper parameter to set? I am asking this since I have to generate a C code for my model for an embedded application and I need to be sure to set an upper threshold for all the variables inside my model. code generation, optimization MATLAB Answers — New Questions
Why is it that Line objects can be instances of two different classes? How can I use findobj to detect only chart primitives?
Using findobj, I have ended up with two arrays of Line graphics handles,
load handleArrays
hL
hD
However, the arrays do not appear to belong to a common class,
whos hL hD
Moreover, even though hD clearly has all the same properties as hL, it cannot be accessed with standard indexing, e.g.,
isprop(hD(1),’Color’)
hD.Color
What is the function of these two different handle graphics types, and how do I tell findobj to retrieve only the hL kind and not the hD kind?Using findobj, I have ended up with two arrays of Line graphics handles,
load handleArrays
hL
hD
However, the arrays do not appear to belong to a common class,
whos hL hD
Moreover, even though hD clearly has all the same properties as hL, it cannot be accessed with standard indexing, e.g.,
isprop(hD(1),’Color’)
hD.Color
What is the function of these two different handle graphics types, and how do I tell findobj to retrieve only the hL kind and not the hD kind? Using findobj, I have ended up with two arrays of Line graphics handles,
load handleArrays
hL
hD
However, the arrays do not appear to belong to a common class,
whos hL hD
Moreover, even though hD clearly has all the same properties as hL, it cannot be accessed with standard indexing, e.g.,
isprop(hD(1),’Color’)
hD.Color
What is the function of these two different handle graphics types, and how do I tell findobj to retrieve only the hL kind and not the hD kind? graphics, line, handles MATLAB Answers — New Questions
How to plot the Unit Step response of a transfer function?
I would like to kindly ask how do I plot the Unit Step response, when given the transfer function.
For instance C = any simple transfer function
How would I plot the Unit Step response of this Transfer Function on any given axes
Many thanks in advance.I would like to kindly ask how do I plot the Unit Step response, when given the transfer function.
For instance C = any simple transfer function
How would I plot the Unit Step response of this Transfer Function on any given axes
Many thanks in advance. I would like to kindly ask how do I plot the Unit Step response, when given the transfer function.
For instance C = any simple transfer function
How would I plot the Unit Step response of this Transfer Function on any given axes
Many thanks in advance. unit step response, plotting MATLAB Answers — New Questions
How to add Get function to the Simulink model generated code
Hello,
I’m generation code from the Simulink model (2 inputs, three outpus). I’d like to add Get function for the output(s), e.g.:
RLS_OnOff LGTC_getRearLightOn(void)
{
return strVarRear.enuRearLightOn;
}
I tried it using Access Data Through Functions with Storage Class GetSet but not successfuly. In the Code Mapping, Data Defaults ribon, I updated Storage class for updates to the "GetSet". But during the code generation I received the folloiwng error message:
In model code mappings, default storage class for outports is set to ‘GetSet’, making generated code noncompliant with function prototype control feature. Set default storage class to ‘Default’.
If I update it to Default to get rid of the error Get function is not created.
Does anybody know how to update the Code generation setting/code mapping to sucessfully build the model to get code containing the Get function for the output?
Thank you very much in advanceHello,
I’m generation code from the Simulink model (2 inputs, three outpus). I’d like to add Get function for the output(s), e.g.:
RLS_OnOff LGTC_getRearLightOn(void)
{
return strVarRear.enuRearLightOn;
}
I tried it using Access Data Through Functions with Storage Class GetSet but not successfuly. In the Code Mapping, Data Defaults ribon, I updated Storage class for updates to the "GetSet". But during the code generation I received the folloiwng error message:
In model code mappings, default storage class for outports is set to ‘GetSet’, making generated code noncompliant with function prototype control feature. Set default storage class to ‘Default’.
If I update it to Default to get rid of the error Get function is not created.
Does anybody know how to update the Code generation setting/code mapping to sucessfully build the model to get code containing the Get function for the output?
Thank you very much in advance Hello,
I’m generation code from the Simulink model (2 inputs, three outpus). I’d like to add Get function for the output(s), e.g.:
RLS_OnOff LGTC_getRearLightOn(void)
{
return strVarRear.enuRearLightOn;
}
I tried it using Access Data Through Functions with Storage Class GetSet but not successfuly. In the Code Mapping, Data Defaults ribon, I updated Storage class for updates to the "GetSet". But during the code generation I received the folloiwng error message:
In model code mappings, default storage class for outports is set to ‘GetSet’, making generated code noncompliant with function prototype control feature. Set default storage class to ‘Default’.
If I update it to Default to get rid of the error Get function is not created.
Does anybody know how to update the Code generation setting/code mapping to sucessfully build the model to get code containing the Get function for the output?
Thank you very much in advance code generation, getset MATLAB Answers — New Questions
Does there exists a built in block in Simulink audio tool to design analog electronic PCB with feedback mechanism ?
Adaptive Filters are core of the ANC system. They continuously adjusts its filter coefficients to minimize the error signal, effectively generating the anti-noise signal. Common choices include the Least Mean Squares (LMS) or Normalized LMS (NLMS) algorithms implemented using the respective Simulink blocks. However if the Anti-noise algorithm is analog electronic PCB with feedback mechanism, then does there exists a built in block in Simulink audio tool to design this algorithm?Adaptive Filters are core of the ANC system. They continuously adjusts its filter coefficients to minimize the error signal, effectively generating the anti-noise signal. Common choices include the Least Mean Squares (LMS) or Normalized LMS (NLMS) algorithms implemented using the respective Simulink blocks. However if the Anti-noise algorithm is analog electronic PCB with feedback mechanism, then does there exists a built in block in Simulink audio tool to design this algorithm? Adaptive Filters are core of the ANC system. They continuously adjusts its filter coefficients to minimize the error signal, effectively generating the anti-noise signal. Common choices include the Least Mean Squares (LMS) or Normalized LMS (NLMS) algorithms implemented using the respective Simulink blocks. However if the Anti-noise algorithm is analog electronic PCB with feedback mechanism, then does there exists a built in block in Simulink audio tool to design this algorithm? simulink, signal flow, acoustic path, active noise cancellation earmuff MATLAB Answers — New Questions
Experiences with release 2012b
Did you try 2012b already? What do you like, what has still potential for further improvements, what makes working with Matlab harder than with earlier releases?
How large is the overlap between the new features and the list of wished changes: <http://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab Answers: what-is-missing-from-matlab>?Did you try 2012b already? What do you like, what has still potential for further improvements, what makes working with Matlab harder than with earlier releases?
How large is the overlap between the new features and the list of wished changes: <http://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab Answers: what-is-missing-from-matlab>? Did you try 2012b already? What do you like, what has still potential for further improvements, what makes working with Matlab harder than with earlier releases?
How large is the overlap between the new features and the list of wished changes: <http://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab Answers: what-is-missing-from-matlab>? r2012b, matlab 8.0, simulink, prefdir MATLAB Answers — New Questions
Unable to acquire the live (streaming) video h264 over rtsp of my ip camera using the “IP camera acquisition” package on Matlab2020b
I am unable to acquire the live (streaming) video of my ip camera using the “IP camera acquisition” package.
Premise:
(1) Operating System: MacOS Big Sur (11.0.1)
(2) Matlab version: 2020b
(3) Installed package: IP camera acquisition packages
(4) Camera type: Dahua DH-IPC-HFW2431TP-ZAS
(5) Camera datasheet: https://www.dahuasecurity.com/asset/upload/uploads/soft/20191015/DH-IPC-HFW2431T-ZAS-S2-datasheet-1910111.pdf
(6) Protocol communication: https://dahuasg.s3-ap-southeast-1.amazonaws.com/DOR/PUM0001827/Dahua%20Network%20Camera%20Web%203.0_Operation%20Manual_V2.0.7.pdf
(7) Link for rtsp streaming: https://dahuawiki.com/Remote_Access/RTSP_via_VLC
I would like to capture live video from my camera using the rtsp link with H264 codec. I did a lot of testing, but never managed to capture the video stream. The rtsp links I used are (7):
rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0
rtsp: //192.168.0.108: 554/live
Both of these links placed on any browser open VLC correctly and the video stream is regularly captured.
Camera data:
IP address: 192.168.0.108
admin: admin
password: admin1993
RTSP port: 554
Resolution: 1080p (I also tried 720p and other formats)
Bit rate: 4096 kbit / s (I did different tests with different rate)
Below I have reported some of the tests carried out:
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0’)
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0′,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’)
I also tried to do some tests by changing the ‘Timeout’ time but to no avail:
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′,’Timeout’,30)
The error generated is always the same:
Cannot connect to the IP Camera Stream URL. Make sure the URL is correct and authentication is provided if needed.
I have read the PDF guide on the MATLAB website several times and I believe I have made all the correct configurations: https://it.mathworks.com/help/pdf_doc/supportpkg/ipcamera/ipcamera_ug.pdf
Can anyone help me to solve this problem?
I thought it was a codec problem or camera settings everything seems fine. I also leave attached a photo of the characteristics of the video stream.
Many thanks in advanceI am unable to acquire the live (streaming) video of my ip camera using the “IP camera acquisition” package.
Premise:
(1) Operating System: MacOS Big Sur (11.0.1)
(2) Matlab version: 2020b
(3) Installed package: IP camera acquisition packages
(4) Camera type: Dahua DH-IPC-HFW2431TP-ZAS
(5) Camera datasheet: https://www.dahuasecurity.com/asset/upload/uploads/soft/20191015/DH-IPC-HFW2431T-ZAS-S2-datasheet-1910111.pdf
(6) Protocol communication: https://dahuasg.s3-ap-southeast-1.amazonaws.com/DOR/PUM0001827/Dahua%20Network%20Camera%20Web%203.0_Operation%20Manual_V2.0.7.pdf
(7) Link for rtsp streaming: https://dahuawiki.com/Remote_Access/RTSP_via_VLC
I would like to capture live video from my camera using the rtsp link with H264 codec. I did a lot of testing, but never managed to capture the video stream. The rtsp links I used are (7):
rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0
rtsp: //192.168.0.108: 554/live
Both of these links placed on any browser open VLC correctly and the video stream is regularly captured.
Camera data:
IP address: 192.168.0.108
admin: admin
password: admin1993
RTSP port: 554
Resolution: 1080p (I also tried 720p and other formats)
Bit rate: 4096 kbit / s (I did different tests with different rate)
Below I have reported some of the tests carried out:
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0’)
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0′,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’)
I also tried to do some tests by changing the ‘Timeout’ time but to no avail:
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′,’Timeout’,30)
The error generated is always the same:
Cannot connect to the IP Camera Stream URL. Make sure the URL is correct and authentication is provided if needed.
I have read the PDF guide on the MATLAB website several times and I believe I have made all the correct configurations: https://it.mathworks.com/help/pdf_doc/supportpkg/ipcamera/ipcamera_ug.pdf
Can anyone help me to solve this problem?
I thought it was a codec problem or camera settings everything seems fine. I also leave attached a photo of the characteristics of the video stream.
Many thanks in advance I am unable to acquire the live (streaming) video of my ip camera using the “IP camera acquisition” package.
Premise:
(1) Operating System: MacOS Big Sur (11.0.1)
(2) Matlab version: 2020b
(3) Installed package: IP camera acquisition packages
(4) Camera type: Dahua DH-IPC-HFW2431TP-ZAS
(5) Camera datasheet: https://www.dahuasecurity.com/asset/upload/uploads/soft/20191015/DH-IPC-HFW2431T-ZAS-S2-datasheet-1910111.pdf
(6) Protocol communication: https://dahuasg.s3-ap-southeast-1.amazonaws.com/DOR/PUM0001827/Dahua%20Network%20Camera%20Web%203.0_Operation%20Manual_V2.0.7.pdf
(7) Link for rtsp streaming: https://dahuawiki.com/Remote_Access/RTSP_via_VLC
I would like to capture live video from my camera using the rtsp link with H264 codec. I did a lot of testing, but never managed to capture the video stream. The rtsp links I used are (7):
rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0
rtsp: //192.168.0.108: 554/live
Both of these links placed on any browser open VLC correctly and the video stream is regularly captured.
Camera data:
IP address: 192.168.0.108
admin: admin
password: admin1993
RTSP port: 554
Resolution: 1080p (I also tried 720p and other formats)
Bit rate: 4096 kbit / s (I did different tests with different rate)
Below I have reported some of the tests carried out:
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0’)
cam = ipcam(‘rtsp://admin:admin1993@192.168.0.108:554/cam/realmonitor?channel=1&subtype=0′,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′)
cam = ipcam(‘rtsp://192.168.0.108:554/live’)
I also tried to do some tests by changing the ‘Timeout’ time but to no avail:
cam = ipcam(‘rtsp://192.168.0.108:554/live’,’admin’,’admin1993′,’Timeout’,30)
The error generated is always the same:
Cannot connect to the IP Camera Stream URL. Make sure the URL is correct and authentication is provided if needed.
I have read the PDF guide on the MATLAB website several times and I believe I have made all the correct configurations: https://it.mathworks.com/help/pdf_doc/supportpkg/ipcamera/ipcamera_ug.pdf
Can anyone help me to solve this problem?
I thought it was a codec problem or camera settings everything seems fine. I also leave attached a photo of the characteristics of the video stream.
Many thanks in advance image acquisition MATLAB Answers — New Questions
How to fix this code trying to create 3 seperate plots from a 3D plots exported to png.
This is code to take all fig files from my map and to convert the to a png, with exception of a 3DPlot, which I want to export as 3 different figures for all axis combinations : X-Y X-Z and Y-Z
the Z axis is not found though.
I made most of this code with AI and am a novice when it comes to coding,
As far as I understand its not finding 3 axis, returning i = 1
returning the following error:
Index exceeds the number of array elements (1).
Error in Fig_to_png_Script (line 27)
copyobj(get(axesHandles(2), ‘Children’), ax2);
I added Numel exceptions in order to skip the error in this version so the code runs and creates only the X-Y plot
% Get all .fig files in the current directory
figFiles = dir(‘*.fig’);
% Loop through each .fig file
for i = 1:length(figFiles)
figName = figFiles(i).name;
% Check if it’s a 3D plot
if contains(figName, ‘3DPlot.fig’, ‘IgnoreCase’, true)
% Load the figure
fig = openfig(figName, ‘invisible’);
% Get handle to the axes
axesHandles = findobj(fig, ‘type’, ‘axes’);
% Handle the X-Y plane (axis 1)
if numel(axesHandles) >= 1
newFig = figure;
ax1 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(1), ‘Children’), ax1);
xlabel(ax1, get(get(axesHandles(1), ‘XLabel’), ‘String’));
ylabel(ax1, get(get(axesHandles(1), ‘YLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_1.png’]);
close(newFig);
end
% Handle the X-Z plane (axis 2)
if numel(axesHandles) >= 2
newFig = figure;
ax2 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(2), ‘Children’), ax2);
xlabel(ax2, get(get(axesHandles(2), ‘XLabel’), ‘String’));
zlabel(ax2, get(get(axesHandles(2), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_2.png’]);
close(newFig);
end
% Handle the Y-Z plane (axis 3)
if numel(axesHandles) >= 3
newFig = figure;
ax3 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(3), ‘Children’), ax3);
ylabel(ax3, get(get(axesHandles(3), ‘YLabel’), ‘String’));
zlabel(ax3, get(get(axesHandles(3), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_3.png’]);
close(newFig);
end
else
% Load the figure
fig = openfig(figName);
% Save as PNG
saveas(fig, [figName ‘.png’]);
% Close the figure
close(fig);
end
endThis is code to take all fig files from my map and to convert the to a png, with exception of a 3DPlot, which I want to export as 3 different figures for all axis combinations : X-Y X-Z and Y-Z
the Z axis is not found though.
I made most of this code with AI and am a novice when it comes to coding,
As far as I understand its not finding 3 axis, returning i = 1
returning the following error:
Index exceeds the number of array elements (1).
Error in Fig_to_png_Script (line 27)
copyobj(get(axesHandles(2), ‘Children’), ax2);
I added Numel exceptions in order to skip the error in this version so the code runs and creates only the X-Y plot
% Get all .fig files in the current directory
figFiles = dir(‘*.fig’);
% Loop through each .fig file
for i = 1:length(figFiles)
figName = figFiles(i).name;
% Check if it’s a 3D plot
if contains(figName, ‘3DPlot.fig’, ‘IgnoreCase’, true)
% Load the figure
fig = openfig(figName, ‘invisible’);
% Get handle to the axes
axesHandles = findobj(fig, ‘type’, ‘axes’);
% Handle the X-Y plane (axis 1)
if numel(axesHandles) >= 1
newFig = figure;
ax1 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(1), ‘Children’), ax1);
xlabel(ax1, get(get(axesHandles(1), ‘XLabel’), ‘String’));
ylabel(ax1, get(get(axesHandles(1), ‘YLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_1.png’]);
close(newFig);
end
% Handle the X-Z plane (axis 2)
if numel(axesHandles) >= 2
newFig = figure;
ax2 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(2), ‘Children’), ax2);
xlabel(ax2, get(get(axesHandles(2), ‘XLabel’), ‘String’));
zlabel(ax2, get(get(axesHandles(2), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_2.png’]);
close(newFig);
end
% Handle the Y-Z plane (axis 3)
if numel(axesHandles) >= 3
newFig = figure;
ax3 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(3), ‘Children’), ax3);
ylabel(ax3, get(get(axesHandles(3), ‘YLabel’), ‘String’));
zlabel(ax3, get(get(axesHandles(3), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_3.png’]);
close(newFig);
end
else
% Load the figure
fig = openfig(figName);
% Save as PNG
saveas(fig, [figName ‘.png’]);
% Close the figure
close(fig);
end
end This is code to take all fig files from my map and to convert the to a png, with exception of a 3DPlot, which I want to export as 3 different figures for all axis combinations : X-Y X-Z and Y-Z
the Z axis is not found though.
I made most of this code with AI and am a novice when it comes to coding,
As far as I understand its not finding 3 axis, returning i = 1
returning the following error:
Index exceeds the number of array elements (1).
Error in Fig_to_png_Script (line 27)
copyobj(get(axesHandles(2), ‘Children’), ax2);
I added Numel exceptions in order to skip the error in this version so the code runs and creates only the X-Y plot
% Get all .fig files in the current directory
figFiles = dir(‘*.fig’);
% Loop through each .fig file
for i = 1:length(figFiles)
figName = figFiles(i).name;
% Check if it’s a 3D plot
if contains(figName, ‘3DPlot.fig’, ‘IgnoreCase’, true)
% Load the figure
fig = openfig(figName, ‘invisible’);
% Get handle to the axes
axesHandles = findobj(fig, ‘type’, ‘axes’);
% Handle the X-Y plane (axis 1)
if numel(axesHandles) >= 1
newFig = figure;
ax1 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(1), ‘Children’), ax1);
xlabel(ax1, get(get(axesHandles(1), ‘XLabel’), ‘String’));
ylabel(ax1, get(get(axesHandles(1), ‘YLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_1.png’]);
close(newFig);
end
% Handle the X-Z plane (axis 2)
if numel(axesHandles) >= 2
newFig = figure;
ax2 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(2), ‘Children’), ax2);
xlabel(ax2, get(get(axesHandles(2), ‘XLabel’), ‘String’));
zlabel(ax2, get(get(axesHandles(2), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_2.png’]);
close(newFig);
end
% Handle the Y-Z plane (axis 3)
if numel(axesHandles) >= 3
newFig = figure;
ax3 = axes(‘Parent’, newFig);
copyobj(get(axesHandles(3), ‘Children’), ax3);
ylabel(ax3, get(get(axesHandles(3), ‘YLabel’), ‘String’));
zlabel(ax3, get(get(axesHandles(3), ‘ZLabel’), ‘String’));
[~, figBaseName, ~] = fileparts(figName);
saveas(newFig, [figBaseName ‘_axis_3.png’]);
close(newFig);
end
else
% Load the figure
fig = openfig(figName);
% Save as PNG
saveas(fig, [figName ‘.png’]);
% Close the figure
close(fig);
end
end plot, getobj, 3dplot, error MATLAB Answers — New Questions
Is It Possible To Enable The “Fit To Content” Formatting Option For Custom Blocks?
Simulink has a nice feature under the "Format" tab called "Fit To Content" that automatically resizes the block so that the mask fits within the mask. I’d like to be able to use this feature for the custom blocks that I create. Is this possible?Simulink has a nice feature under the "Format" tab called "Fit To Content" that automatically resizes the block so that the mask fits within the mask. I’d like to be able to use this feature for the custom blocks that I create. Is this possible? Simulink has a nice feature under the "Format" tab called "Fit To Content" that automatically resizes the block so that the mask fits within the mask. I’d like to be able to use this feature for the custom blocks that I create. Is this possible? simulink MATLAB Answers — New Questions
Read all lines of binary file at once
Hello! My code currently opens 120 folders one by one and each folder contains 2 binary files. The code then opens each binary file one by one and reads it. These binary files have 1250 lines each and the lines are read once again one by one.
Is it possible to have the code read all of the lines of 1 binary file at once, not go through 1250 lines sequentially?
The format of the first line is ‘int int int int int int’ (6x int) and the format of all other lines is ‘int char float float float float float float’ (1x int, 1x char, 6x float). The code can be found below.
If there are other suggestions for speeding up the code, please do mention them.
listing = dir(ResultsFolder); % Folder with all 120 folders
for i = 1:length(listing) % Goes from 1 to 120
FieldFolder = [listing(i).folder ” listing(i).name]; % Open 1 of the 120 folders
listingFields = dir(FieldFolder);
FieldFiles = listingFields(contains({listingFields.name},sprintf(‘%A.fld’))); % Get the 2 binary files of interest
for j = 1:length(FieldFiles) % Goes from 1 to 2
fileID = fopen([FieldFolder ” FieldFiles(j).name]); % Open binary file
k = 1;
fileEnd = false;
while ~fileEnd % Read all of the 1250 lines
% FirstLineFormat=’int int int int int int’
% OtherLineFormat=’int char float float float float float float’
try
if k == 1
FieldData_tmp(k,:) = [fread(fileID, 6, ‘int’)’ 0 0 ]; % Read first line
else
FieldData_tmp(k,:) = [fread(fileID, 1, ‘int’) fread(fileID, 1, ‘char’) fread(fileID, 6, ‘float’)’]; % Read other lines
end
catch
fileEnd = true; % No lines left
end
k = k+1;
end
fclose(fileID);
end
endHello! My code currently opens 120 folders one by one and each folder contains 2 binary files. The code then opens each binary file one by one and reads it. These binary files have 1250 lines each and the lines are read once again one by one.
Is it possible to have the code read all of the lines of 1 binary file at once, not go through 1250 lines sequentially?
The format of the first line is ‘int int int int int int’ (6x int) and the format of all other lines is ‘int char float float float float float float’ (1x int, 1x char, 6x float). The code can be found below.
If there are other suggestions for speeding up the code, please do mention them.
listing = dir(ResultsFolder); % Folder with all 120 folders
for i = 1:length(listing) % Goes from 1 to 120
FieldFolder = [listing(i).folder ” listing(i).name]; % Open 1 of the 120 folders
listingFields = dir(FieldFolder);
FieldFiles = listingFields(contains({listingFields.name},sprintf(‘%A.fld’))); % Get the 2 binary files of interest
for j = 1:length(FieldFiles) % Goes from 1 to 2
fileID = fopen([FieldFolder ” FieldFiles(j).name]); % Open binary file
k = 1;
fileEnd = false;
while ~fileEnd % Read all of the 1250 lines
% FirstLineFormat=’int int int int int int’
% OtherLineFormat=’int char float float float float float float’
try
if k == 1
FieldData_tmp(k,:) = [fread(fileID, 6, ‘int’)’ 0 0 ]; % Read first line
else
FieldData_tmp(k,:) = [fread(fileID, 1, ‘int’) fread(fileID, 1, ‘char’) fread(fileID, 6, ‘float’)’]; % Read other lines
end
catch
fileEnd = true; % No lines left
end
k = k+1;
end
fclose(fileID);
end
end Hello! My code currently opens 120 folders one by one and each folder contains 2 binary files. The code then opens each binary file one by one and reads it. These binary files have 1250 lines each and the lines are read once again one by one.
Is it possible to have the code read all of the lines of 1 binary file at once, not go through 1250 lines sequentially?
The format of the first line is ‘int int int int int int’ (6x int) and the format of all other lines is ‘int char float float float float float float’ (1x int, 1x char, 6x float). The code can be found below.
If there are other suggestions for speeding up the code, please do mention them.
listing = dir(ResultsFolder); % Folder with all 120 folders
for i = 1:length(listing) % Goes from 1 to 120
FieldFolder = [listing(i).folder ” listing(i).name]; % Open 1 of the 120 folders
listingFields = dir(FieldFolder);
FieldFiles = listingFields(contains({listingFields.name},sprintf(‘%A.fld’))); % Get the 2 binary files of interest
for j = 1:length(FieldFiles) % Goes from 1 to 2
fileID = fopen([FieldFolder ” FieldFiles(j).name]); % Open binary file
k = 1;
fileEnd = false;
while ~fileEnd % Read all of the 1250 lines
% FirstLineFormat=’int int int int int int’
% OtherLineFormat=’int char float float float float float float’
try
if k == 1
FieldData_tmp(k,:) = [fread(fileID, 6, ‘int’)’ 0 0 ]; % Read first line
else
FieldData_tmp(k,:) = [fread(fileID, 1, ‘int’) fread(fileID, 1, ‘char’) fread(fileID, 6, ‘float’)’]; % Read other lines
end
catch
fileEnd = true; % No lines left
end
k = k+1;
end
fclose(fileID);
end
end binary MATLAB Answers — New Questions
binwin64nativejava_engine_core.dll: Can’t find dependent libraries
Start MATLAB from Java synchronously.
import com.mathworks.engine.*;
public class StartMatlab {
public static void main(String[] args) throws Exception {
MatlabEngine eng = MatlabEngine.startMatlab();
…
eng.close();
}
}
java.lang.UnsatisfiedLinkError:<matlabroot>binwin64nativejava_engine_core.dll: Can’t find dependent libraries。
Fixed missing files using dependencywalker, but still reported an error. System environment variables have been added. How can I resolve this issueStart MATLAB from Java synchronously.
import com.mathworks.engine.*;
public class StartMatlab {
public static void main(String[] args) throws Exception {
MatlabEngine eng = MatlabEngine.startMatlab();
…
eng.close();
}
}
java.lang.UnsatisfiedLinkError:<matlabroot>binwin64nativejava_engine_core.dll: Can’t find dependent libraries。
Fixed missing files using dependencywalker, but still reported an error. System environment variables have been added. How can I resolve this issue Start MATLAB from Java synchronously.
import com.mathworks.engine.*;
public class StartMatlab {
public static void main(String[] args) throws Exception {
MatlabEngine eng = MatlabEngine.startMatlab();
…
eng.close();
}
}
java.lang.UnsatisfiedLinkError:<matlabroot>binwin64nativejava_engine_core.dll: Can’t find dependent libraries。
Fixed missing files using dependencywalker, but still reported an error. System environment variables have been added. How can I resolve this issue matlab/matlab-engine-api-for-java MATLAB Answers — New Questions
Test Manager: No block called ‘From1’ could be found.
Hello,
I’m working on a model and try to write test through Test Manager.
The model is updating without error => OK
When I run the test in Test Manager, I can see the following step in the Simulink test harness window:
…
Updating library link blocks: Completed
( It updates the 4 referenced model,)
Compiling: Refreshing bus cache: Completed
Compiling: Evaluating block parameters: Completed
Initializing
Ready
Then it stops, and in the Test Manager window, the following error appears:
Cause of Failure: Erros running test case
Invalid Simulink object name: Toto_Sequence_Harness/From1.
No block called ‘From1’ could be found.
As mentionned in another post, a space character can be the origin of the error. I look for ‘ From1’ (sapce before) and ‘From1 ‘ (space after) but Simulink didn’t find any.
In the model there are 1602 ‘From1’ (without space, it includes ‘From10’, ‘From11’…).
How can I have more precision regarding error location ?
How can this error can be solved ?
Thanks in advance,
ChristopheHello,
I’m working on a model and try to write test through Test Manager.
The model is updating without error => OK
When I run the test in Test Manager, I can see the following step in the Simulink test harness window:
…
Updating library link blocks: Completed
( It updates the 4 referenced model,)
Compiling: Refreshing bus cache: Completed
Compiling: Evaluating block parameters: Completed
Initializing
Ready
Then it stops, and in the Test Manager window, the following error appears:
Cause of Failure: Erros running test case
Invalid Simulink object name: Toto_Sequence_Harness/From1.
No block called ‘From1’ could be found.
As mentionned in another post, a space character can be the origin of the error. I look for ‘ From1’ (sapce before) and ‘From1 ‘ (space after) but Simulink didn’t find any.
In the model there are 1602 ‘From1’ (without space, it includes ‘From10’, ‘From11’…).
How can I have more precision regarding error location ?
How can this error can be solved ?
Thanks in advance,
Christophe Hello,
I’m working on a model and try to write test through Test Manager.
The model is updating without error => OK
When I run the test in Test Manager, I can see the following step in the Simulink test harness window:
…
Updating library link blocks: Completed
( It updates the 4 referenced model,)
Compiling: Refreshing bus cache: Completed
Compiling: Evaluating block parameters: Completed
Initializing
Ready
Then it stops, and in the Test Manager window, the following error appears:
Cause of Failure: Erros running test case
Invalid Simulink object name: Toto_Sequence_Harness/From1.
No block called ‘From1’ could be found.
As mentionned in another post, a space character can be the origin of the error. I look for ‘ From1’ (sapce before) and ‘From1 ‘ (space after) but Simulink didn’t find any.
In the model there are 1602 ‘From1’ (without space, it includes ‘From10’, ‘From11’…).
How can I have more precision regarding error location ?
How can this error can be solved ?
Thanks in advance,
Christophe no block called could be found, invalid simulink object name MATLAB Answers — New Questions
Simscape begins simulation outside of joint limits
I am trying to model a closed kinematic chain in simulink, and i get problems with having meaningful initialization. Matlab ignores the joint limits for some joints.
What i have done:
I imported a urdf (which it self doesn’t close the chain) and added a bushing joint to close the chain at the required point). There are 5 links, but only three of them are independent (and actuated), thus i have set a position target to those with high priority (to set the desired initial conditions). In the bushing joint, in all the DOFs i want to constraint i have set a position target to zero with low priority.
Thus, the 2 unactuated joints do not have a specified position target and are passive joints.
Problem
When i launch the simulation at specified initial conditions, matlab ignores the limits of the unactuated joint to close the chain, even though there is a solution. See below: (1.22 rad ~= 70 deg)
This causes the closed chain to get in a weird configuration, instead of the sketched one:
Also, the next step in the simulation, puts the configuration in the acceptable limits:
So it is like the limits are not respected when simscape tries to close the chainI am trying to model a closed kinematic chain in simulink, and i get problems with having meaningful initialization. Matlab ignores the joint limits for some joints.
What i have done:
I imported a urdf (which it self doesn’t close the chain) and added a bushing joint to close the chain at the required point). There are 5 links, but only three of them are independent (and actuated), thus i have set a position target to those with high priority (to set the desired initial conditions). In the bushing joint, in all the DOFs i want to constraint i have set a position target to zero with low priority.
Thus, the 2 unactuated joints do not have a specified position target and are passive joints.
Problem
When i launch the simulation at specified initial conditions, matlab ignores the limits of the unactuated joint to close the chain, even though there is a solution. See below: (1.22 rad ~= 70 deg)
This causes the closed chain to get in a weird configuration, instead of the sketched one:
Also, the next step in the simulation, puts the configuration in the acceptable limits:
So it is like the limits are not respected when simscape tries to close the chain I am trying to model a closed kinematic chain in simulink, and i get problems with having meaningful initialization. Matlab ignores the joint limits for some joints.
What i have done:
I imported a urdf (which it self doesn’t close the chain) and added a bushing joint to close the chain at the required point). There are 5 links, but only three of them are independent (and actuated), thus i have set a position target to those with high priority (to set the desired initial conditions). In the bushing joint, in all the DOFs i want to constraint i have set a position target to zero with low priority.
Thus, the 2 unactuated joints do not have a specified position target and are passive joints.
Problem
When i launch the simulation at specified initial conditions, matlab ignores the limits of the unactuated joint to close the chain, even though there is a solution. See below: (1.22 rad ~= 70 deg)
This causes the closed chain to get in a weird configuration, instead of the sketched one:
Also, the next step in the simulation, puts the configuration in the acceptable limits:
So it is like the limits are not respected when simscape tries to close the chain simulink, simscape, simulation MATLAB Answers — New Questions
cgs algorithm not working with function defined system matrix
%% in following code i am trying to get forward diffraction using a point spread function given by psf
% whole pipeline is given as Au=uin, in which A=psf * original image.*u, u is to be estimated and uin is input .
% A is defined via a function which doe convolution between psf and elemsnt wise multiplication of original image and u.
%i tried to implement it but getting error as "Arrays have incompatile size for this opeartion , can someone hlep me rectify it.
%% this code contains only conjugate gradient based method for image reconstruction
clc
clear all;
close all;
% Load the original image
original_image = im2double(imread(‘cameraman.tif’));
N=size(original_image,1);
psf = green_f1(N);
% Normalize the PSF
psf = psf / sum(psf(:));
incident_field=ones(N,N);
I=eye(size(original_image));
I=I(:);
% Define the system matrix
A = @(x) convolution2(x.*original_image, psf);
At = @(x) convolution2(x, conj(flipud(fliplr(psf))));
% Define parameters for conjugate gradient method
max_iter = 100; % Maximum number of iterations
tol = 1e-8; % Tolerance for convergence
% Conjugate gradient method
b=incident_field(:);
%b = degraded_image(:);
x0=rand(N,N);
x0=x0(:);
%x0 = estimated_image(:);
[x, ~, relres, iter] = cgs(A, b, tol, max_iter, [], [], x0);
% Reshape the result to image size
estimated_image = reshape(x, size(degraded_image));
% Display the deconvolved image
figure;
imshow(estimated_image); title(‘Deconvolved Image’);
% Helper function for 2D convolution
function y = convolution2(x, h)
y = ifft2(fft2(x) .* fft2(h, size(x,1), size(x,2)));
end
function G=green_f1(N) ;
% Input parameters
% N=512; % Number of pixels
L=10; %e-6; % Length of the field of view (in meters)
rad=30e-6; % Radius of aperture (in meters)
lambda=0.630;%e-9; % Wavelength of light (in meters)
z=100e-6; %Propagation distance (in meters)
% Coordinate vectors/grids
dx=L/N; % Length of one pixel
x=-L/2 : dx : L/2-dx; % Coordinate vector (in meters)
fx=-1/(2*dx):1/L:1/(2*dx)-1/L; % Spatial frequency vector (in 1/meters)
[X,Y]=meshgrid(x,x); % Coordinate grids (real space)
[FX,FY]=meshgrid(fx,fx); % Coordinate grids (Fourier space)
% Define aperture
R=sqrt(X.^2+Y.^2); % Radial coordinate
R(R==0) = 1; % Avoid division by zero
%Aperture=double(R<rad); % Aperture
nb=1.351; % refractive index background
kg=2*pi/lambda; % wavenumber
%p=parpool(4);
nn=size(R,2);
for i=1:size(R,1)
%for i=1:size(r,1)
for j=1:nn
G(i,j)= (exp(1i*(kg*R(i,j)*nb)))/(4*pi*R(i,j));
end
end
end%% in following code i am trying to get forward diffraction using a point spread function given by psf
% whole pipeline is given as Au=uin, in which A=psf * original image.*u, u is to be estimated and uin is input .
% A is defined via a function which doe convolution between psf and elemsnt wise multiplication of original image and u.
%i tried to implement it but getting error as "Arrays have incompatile size for this opeartion , can someone hlep me rectify it.
%% this code contains only conjugate gradient based method for image reconstruction
clc
clear all;
close all;
% Load the original image
original_image = im2double(imread(‘cameraman.tif’));
N=size(original_image,1);
psf = green_f1(N);
% Normalize the PSF
psf = psf / sum(psf(:));
incident_field=ones(N,N);
I=eye(size(original_image));
I=I(:);
% Define the system matrix
A = @(x) convolution2(x.*original_image, psf);
At = @(x) convolution2(x, conj(flipud(fliplr(psf))));
% Define parameters for conjugate gradient method
max_iter = 100; % Maximum number of iterations
tol = 1e-8; % Tolerance for convergence
% Conjugate gradient method
b=incident_field(:);
%b = degraded_image(:);
x0=rand(N,N);
x0=x0(:);
%x0 = estimated_image(:);
[x, ~, relres, iter] = cgs(A, b, tol, max_iter, [], [], x0);
% Reshape the result to image size
estimated_image = reshape(x, size(degraded_image));
% Display the deconvolved image
figure;
imshow(estimated_image); title(‘Deconvolved Image’);
% Helper function for 2D convolution
function y = convolution2(x, h)
y = ifft2(fft2(x) .* fft2(h, size(x,1), size(x,2)));
end
function G=green_f1(N) ;
% Input parameters
% N=512; % Number of pixels
L=10; %e-6; % Length of the field of view (in meters)
rad=30e-6; % Radius of aperture (in meters)
lambda=0.630;%e-9; % Wavelength of light (in meters)
z=100e-6; %Propagation distance (in meters)
% Coordinate vectors/grids
dx=L/N; % Length of one pixel
x=-L/2 : dx : L/2-dx; % Coordinate vector (in meters)
fx=-1/(2*dx):1/L:1/(2*dx)-1/L; % Spatial frequency vector (in 1/meters)
[X,Y]=meshgrid(x,x); % Coordinate grids (real space)
[FX,FY]=meshgrid(fx,fx); % Coordinate grids (Fourier space)
% Define aperture
R=sqrt(X.^2+Y.^2); % Radial coordinate
R(R==0) = 1; % Avoid division by zero
%Aperture=double(R<rad); % Aperture
nb=1.351; % refractive index background
kg=2*pi/lambda; % wavenumber
%p=parpool(4);
nn=size(R,2);
for i=1:size(R,1)
%for i=1:size(r,1)
for j=1:nn
G(i,j)= (exp(1i*(kg*R(i,j)*nb)))/(4*pi*R(i,j));
end
end
end %% in following code i am trying to get forward diffraction using a point spread function given by psf
% whole pipeline is given as Au=uin, in which A=psf * original image.*u, u is to be estimated and uin is input .
% A is defined via a function which doe convolution between psf and elemsnt wise multiplication of original image and u.
%i tried to implement it but getting error as "Arrays have incompatile size for this opeartion , can someone hlep me rectify it.
%% this code contains only conjugate gradient based method for image reconstruction
clc
clear all;
close all;
% Load the original image
original_image = im2double(imread(‘cameraman.tif’));
N=size(original_image,1);
psf = green_f1(N);
% Normalize the PSF
psf = psf / sum(psf(:));
incident_field=ones(N,N);
I=eye(size(original_image));
I=I(:);
% Define the system matrix
A = @(x) convolution2(x.*original_image, psf);
At = @(x) convolution2(x, conj(flipud(fliplr(psf))));
% Define parameters for conjugate gradient method
max_iter = 100; % Maximum number of iterations
tol = 1e-8; % Tolerance for convergence
% Conjugate gradient method
b=incident_field(:);
%b = degraded_image(:);
x0=rand(N,N);
x0=x0(:);
%x0 = estimated_image(:);
[x, ~, relres, iter] = cgs(A, b, tol, max_iter, [], [], x0);
% Reshape the result to image size
estimated_image = reshape(x, size(degraded_image));
% Display the deconvolved image
figure;
imshow(estimated_image); title(‘Deconvolved Image’);
% Helper function for 2D convolution
function y = convolution2(x, h)
y = ifft2(fft2(x) .* fft2(h, size(x,1), size(x,2)));
end
function G=green_f1(N) ;
% Input parameters
% N=512; % Number of pixels
L=10; %e-6; % Length of the field of view (in meters)
rad=30e-6; % Radius of aperture (in meters)
lambda=0.630;%e-9; % Wavelength of light (in meters)
z=100e-6; %Propagation distance (in meters)
% Coordinate vectors/grids
dx=L/N; % Length of one pixel
x=-L/2 : dx : L/2-dx; % Coordinate vector (in meters)
fx=-1/(2*dx):1/L:1/(2*dx)-1/L; % Spatial frequency vector (in 1/meters)
[X,Y]=meshgrid(x,x); % Coordinate grids (real space)
[FX,FY]=meshgrid(fx,fx); % Coordinate grids (Fourier space)
% Define aperture
R=sqrt(X.^2+Y.^2); % Radial coordinate
R(R==0) = 1; % Avoid division by zero
%Aperture=double(R<rad); % Aperture
nb=1.351; % refractive index background
kg=2*pi/lambda; % wavenumber
%p=parpool(4);
nn=size(R,2);
for i=1:size(R,1)
%for i=1:size(r,1)
for j=1:nn
G(i,j)= (exp(1i*(kg*R(i,j)*nb)))/(4*pi*R(i,j));
end
end
end optimization using cgs, matlab MATLAB Answers — New Questions
Can I charactrize LFP cell in “Characterize Battery Cell for Electric Vehicles”?
Can I charactrize LFP cell in "Characterize Battery Cell for Electric Vehicles"?Can I charactrize LFP cell in "Characterize Battery Cell for Electric Vehicles"? Can I charactrize LFP cell in "Characterize Battery Cell for Electric Vehicles"? battery MATLAB Answers — New Questions
datetime adjustment in x-axis plot
Hello everyone,
i want to adjust my datetime x-axis in pcolor plot in matlab but i tried but it doesnt working. I add my data here and code also
x = [01-01-2021 00:00 01-01-2021 00:14 01-01-2021 00:28 01-02-2021 00:42] like this one year data for 14 min intervel
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32]
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04]
Code:1
pcolor(datenum(x),y,z)
shading interp
a = gca;
set(a,’XTick’);
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’,’keeplimits’); # tried this it is showing only few date points
(or)
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’); # tried this it is also showing only few date points
Code:2
pcolor(datenum(date1),y,z)
a = gca;
a.XTick = datenum(x);
a.XTickLabel = datestr(datenum(x)); # in this code it is taking as a text and displaying all the points
I just want to show in my x-axis like Jan, Feb, Mar, till Dec or daily one point or 10 days once one point like Jan 10 Jan 20 Jan 30 Feb 10 etc.
I tried alot but i couldnt able to make this i am waiting for the help from the experts.
Thank you in advance.Hello everyone,
i want to adjust my datetime x-axis in pcolor plot in matlab but i tried but it doesnt working. I add my data here and code also
x = [01-01-2021 00:00 01-01-2021 00:14 01-01-2021 00:28 01-02-2021 00:42] like this one year data for 14 min intervel
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32]
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04]
Code:1
pcolor(datenum(x),y,z)
shading interp
a = gca;
set(a,’XTick’);
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’,’keeplimits’); # tried this it is showing only few date points
(or)
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’); # tried this it is also showing only few date points
Code:2
pcolor(datenum(date1),y,z)
a = gca;
a.XTick = datenum(x);
a.XTickLabel = datestr(datenum(x)); # in this code it is taking as a text and displaying all the points
I just want to show in my x-axis like Jan, Feb, Mar, till Dec or daily one point or 10 days once one point like Jan 10 Jan 20 Jan 30 Feb 10 etc.
I tried alot but i couldnt able to make this i am waiting for the help from the experts.
Thank you in advance. Hello everyone,
i want to adjust my datetime x-axis in pcolor plot in matlab but i tried but it doesnt working. I add my data here and code also
x = [01-01-2021 00:00 01-01-2021 00:14 01-01-2021 00:28 01-02-2021 00:42] like this one year data for 14 min intervel
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32]
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04]
Code:1
pcolor(datenum(x),y,z)
shading interp
a = gca;
set(a,’XTick’);
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’,’keeplimits’); # tried this it is showing only few date points
(or)
datetick(‘x’,’dd-mmm HH:MM’,’keepticks’); # tried this it is also showing only few date points
Code:2
pcolor(datenum(date1),y,z)
a = gca;
a.XTick = datenum(x);
a.XTickLabel = datestr(datenum(x)); # in this code it is taking as a text and displaying all the points
I just want to show in my x-axis like Jan, Feb, Mar, till Dec or daily one point or 10 days once one point like Jan 10 Jan 20 Jan 30 Feb 10 etc.
I tried alot but i couldnt able to make this i am waiting for the help from the experts.
Thank you in advance. matlab, matlab code, matlab coder MATLAB Answers — New Questions
How to specify column names by writematrix function in Appdesigner?
I’m working in app designer. I store 4 columns of data to an excell file.
I have already specified the column names in excell and am using "VariableNamingRule", "preserve". But the column names are transformed into Var1, Var2 etc. or all column names are disappeared.
How do l solve this problem?
Thanks in advance!I’m working in app designer. I store 4 columns of data to an excell file.
I have already specified the column names in excell and am using "VariableNamingRule", "preserve". But the column names are transformed into Var1, Var2 etc. or all column names are disappeared.
How do l solve this problem?
Thanks in advance! I’m working in app designer. I store 4 columns of data to an excell file.
I have already specified the column names in excell and am using "VariableNamingRule", "preserve". But the column names are transformed into Var1, Var2 etc. or all column names are disappeared.
How do l solve this problem?
Thanks in advance! matrix, excel, export, data MATLAB Answers — New Questions
Is fftshift not working here ?
I have a set of data from a thermocouple
I have this data in the form of a text file and importated it into matlab without issue
When trying to apply an fft() to this data set the output seemed fine
But when trying to apply an fftshift() it seemed to not work
in the sense that it produced a graph which looked identical to just the plotting of the voltage against time
This is the code showing how the shiftedFFT is identitical to the plotting of the voltage against time
I have a sneaking suspsion that im supposed to apply the fftshift to the data ive already applied the fft to but im not sure
clear,clearvars, close,clc
Scope_Data = load("Data from scope 2.txt");
Time_Data = Scope_Data(:,1);
Volatge_Data = Scope_Data(:,2);
Real_Data = real(fftshift(Volatge_Data,8192));
Img_Data = imag(fftshift(Volatge_Data,8192));
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,2,3)
plot(Volatge_Data)I have a set of data from a thermocouple
I have this data in the form of a text file and importated it into matlab without issue
When trying to apply an fft() to this data set the output seemed fine
But when trying to apply an fftshift() it seemed to not work
in the sense that it produced a graph which looked identical to just the plotting of the voltage against time
This is the code showing how the shiftedFFT is identitical to the plotting of the voltage against time
I have a sneaking suspsion that im supposed to apply the fftshift to the data ive already applied the fft to but im not sure
clear,clearvars, close,clc
Scope_Data = load("Data from scope 2.txt");
Time_Data = Scope_Data(:,1);
Volatge_Data = Scope_Data(:,2);
Real_Data = real(fftshift(Volatge_Data,8192));
Img_Data = imag(fftshift(Volatge_Data,8192));
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,2,3)
plot(Volatge_Data) I have a set of data from a thermocouple
I have this data in the form of a text file and importated it into matlab without issue
When trying to apply an fft() to this data set the output seemed fine
But when trying to apply an fftshift() it seemed to not work
in the sense that it produced a graph which looked identical to just the plotting of the voltage against time
This is the code showing how the shiftedFFT is identitical to the plotting of the voltage against time
I have a sneaking suspsion that im supposed to apply the fftshift to the data ive already applied the fft to but im not sure
clear,clearvars, close,clc
Scope_Data = load("Data from scope 2.txt");
Time_Data = Scope_Data(:,1);
Volatge_Data = Scope_Data(:,2);
Real_Data = real(fftshift(Volatge_Data,8192));
Img_Data = imag(fftshift(Volatge_Data,8192));
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,3,1)
plot(Real_Data)
xlabel("Frequency Index")
ylabel("Real Part of FFT of Signal")
title("Real_fftshift")
subplot(2,2,2)
plot(Img_Data)
xlabel("Frequency Index")
ylabel("Img Part of FFT of Signal")
title("Img_fftshift")
subplot(2,2,3)
plot(Volatge_Data) fft, fftshift MATLAB Answers — New Questions