Tag Archives: matlab
¿Could you help me to activate MatLab?
I had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime TamaritI had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime Tamarit I had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime Tamarit activation of matlab MATLAB Answers — New Questions
Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02.
I want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
endI want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
end I want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
end fsolve, solving systems of nonlinear equations MATLAB Answers — New Questions
How to run two simulink models in parallel?
Hello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank youHello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank you Hello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank you simulink, subsystem, scope MATLAB Answers — New Questions
Save a stack of 16-bit images to one TIFF file
Hi,
I would like to save a stack (in this case 150) of uint16 grayscale images to a single TIFF-file. First I tried pass over the 3D-array (the third dimension are the individual images) to imwrite, but it complained "Writing TIFFs with 150 components is not supported with IMWRITE. Use Tiff instead. ". I tried this (imgdata is my 3D-array of images):
imgdata = uint16(imgdata);
tagstruct.ImageLength = size(imgdata,1);
tagstruct.ImageWidth = size(imgdata,2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = ‘MATLAB’;
tagstruct.Compression = 1;
t = Tiff(path,’w’);
setTag(t,tagstruct);
write(t,imgdata);
I got the error message "SamplesPerPixel is 1, but the number of image planes provided was 150.", so write() interprets the third dimension as the samples per pixel, which is not what I want. Samples per Pixel needs to be 1, as I have grayscale images.
After that, I also tried it with the "append" option and a loop over the images (with the same tagstruct as above)
t = Tiff(path,’a’);
setTag(t,tagstruct);
numberOfImages = size(imgdata,3);
for n=1:numberOfImages
currentImage = squeeze(imgdata(:,:,n));
write(t,currentImage);
end
close(t);
It runs without errors and the file size of the uncompressed file is exactly what I would expect, so I think the data is in the file. But I can’t open the file in any other software than matlab. Irfanview, imageJ, Windows image viewer all show just the first image of the stack.
Any ideas what’s wrong? Thanks.Hi,
I would like to save a stack (in this case 150) of uint16 grayscale images to a single TIFF-file. First I tried pass over the 3D-array (the third dimension are the individual images) to imwrite, but it complained "Writing TIFFs with 150 components is not supported with IMWRITE. Use Tiff instead. ". I tried this (imgdata is my 3D-array of images):
imgdata = uint16(imgdata);
tagstruct.ImageLength = size(imgdata,1);
tagstruct.ImageWidth = size(imgdata,2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = ‘MATLAB’;
tagstruct.Compression = 1;
t = Tiff(path,’w’);
setTag(t,tagstruct);
write(t,imgdata);
I got the error message "SamplesPerPixel is 1, but the number of image planes provided was 150.", so write() interprets the third dimension as the samples per pixel, which is not what I want. Samples per Pixel needs to be 1, as I have grayscale images.
After that, I also tried it with the "append" option and a loop over the images (with the same tagstruct as above)
t = Tiff(path,’a’);
setTag(t,tagstruct);
numberOfImages = size(imgdata,3);
for n=1:numberOfImages
currentImage = squeeze(imgdata(:,:,n));
write(t,currentImage);
end
close(t);
It runs without errors and the file size of the uncompressed file is exactly what I would expect, so I think the data is in the file. But I can’t open the file in any other software than matlab. Irfanview, imageJ, Windows image viewer all show just the first image of the stack.
Any ideas what’s wrong? Thanks. Hi,
I would like to save a stack (in this case 150) of uint16 grayscale images to a single TIFF-file. First I tried pass over the 3D-array (the third dimension are the individual images) to imwrite, but it complained "Writing TIFFs with 150 components is not supported with IMWRITE. Use Tiff instead. ". I tried this (imgdata is my 3D-array of images):
imgdata = uint16(imgdata);
tagstruct.ImageLength = size(imgdata,1);
tagstruct.ImageWidth = size(imgdata,2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = ‘MATLAB’;
tagstruct.Compression = 1;
t = Tiff(path,’w’);
setTag(t,tagstruct);
write(t,imgdata);
I got the error message "SamplesPerPixel is 1, but the number of image planes provided was 150.", so write() interprets the third dimension as the samples per pixel, which is not what I want. Samples per Pixel needs to be 1, as I have grayscale images.
After that, I also tried it with the "append" option and a loop over the images (with the same tagstruct as above)
t = Tiff(path,’a’);
setTag(t,tagstruct);
numberOfImages = size(imgdata,3);
for n=1:numberOfImages
currentImage = squeeze(imgdata(:,:,n));
write(t,currentImage);
end
close(t);
It runs without errors and the file size of the uncompressed file is exactly what I would expect, so I think the data is in the file. But I can’t open the file in any other software than matlab. Irfanview, imageJ, Windows image viewer all show just the first image of the stack.
Any ideas what’s wrong? Thanks. tif, tiff, multipage tiff, imwrite MATLAB Answers — New Questions
Error using readtable: An error occurred while trying to determine whether “readData” is a function name
I get the following error when I am calling
readtable(‘file.csv’)
Error using readtable (line 197)
An error occurred while trying to determine whether "readData" is a function name.
Note: readtable detected the following parameters:
‘Delimiter’, ‘,’, ‘HeaderLines’, , ‘Format’, ”
Can you please help me on this one (do not provide me links on the same topic, I have checked everything and nothing is working) ?I get the following error when I am calling
readtable(‘file.csv’)
Error using readtable (line 197)
An error occurred while trying to determine whether "readData" is a function name.
Note: readtable detected the following parameters:
‘Delimiter’, ‘,’, ‘HeaderLines’, , ‘Format’, ”
Can you please help me on this one (do not provide me links on the same topic, I have checked everything and nothing is working) ? I get the following error when I am calling
readtable(‘file.csv’)
Error using readtable (line 197)
An error occurred while trying to determine whether "readData" is a function name.
Note: readtable detected the following parameters:
‘Delimiter’, ‘,’, ‘HeaderLines’, , ‘Format’, ”
Can you please help me on this one (do not provide me links on the same topic, I have checked everything and nothing is working) ? readtable MATLAB Answers — New Questions
Which UHD version is compatible for MATLAB 2023a
I have a computer which is not connected to internet and I have NI USRP 2954R, and both are connected via LAN cable. The computer is not connected to the internet. So, I can’t download the communications toolbox directly through MATLAB software. So, can anyone tell me which UHD(Which is to be downloaded from ettus website) version is compatible with MATLAB 2023b?I have a computer which is not connected to internet and I have NI USRP 2954R, and both are connected via LAN cable. The computer is not connected to the internet. So, I can’t download the communications toolbox directly through MATLAB software. So, can anyone tell me which UHD(Which is to be downloaded from ettus website) version is compatible with MATLAB 2023b? I have a computer which is not connected to internet and I have NI USRP 2954R, and both are connected via LAN cable. The computer is not connected to the internet. So, I can’t download the communications toolbox directly through MATLAB software. So, can anyone tell me which UHD(Which is to be downloaded from ettus website) version is compatible with MATLAB 2023b? ettus, matlab2023b, national instruments, usrp, uhd MATLAB Answers — New Questions
Remove exponentials with positive argument in symbolic MATLAB
Hello!
I am using symbolic MATLAB to obtain an expression of the form:
Where are some complicated expresions of other variables. To avoid problems with numeric evaluation, I would like to express the expression in the form:
Is there a way to easily implement that on MATLAB?
Thanks!Hello!
I am using symbolic MATLAB to obtain an expression of the form:
Where are some complicated expresions of other variables. To avoid problems with numeric evaluation, I would like to express the expression in the form:
Is there a way to easily implement that on MATLAB?
Thanks! Hello!
I am using symbolic MATLAB to obtain an expression of the form:
Where are some complicated expresions of other variables. To avoid problems with numeric evaluation, I would like to express the expression in the form:
Is there a way to easily implement that on MATLAB?
Thanks! exponential, simplification MATLAB Answers — New Questions
Latitude and Longitude of Path from A to B
Hi all,
Is there a premade function in Matlab that can gives sets of latitude and longitude of the shortest possible routes (like GPS) from one place to another (represented also as latitude longtitude)
So the *input* is:
Latitude and Longitude of a place A
Latitude and Longitude of a place B
The *output* is:
set of latitudes and longitudes of route 1 from A to B in a matrix
set of latitudes and longitudes of route 2 from A to B in a matrix
set of latitudes and longitudes of route 3 from A to B in a matrix
etc…..
The number of points of latitudes and longitudes in the output would depend on another input that describe how details the output would be.
Might be very complex things to do.
Thanks a lot in advance for any suggestion.Hi all,
Is there a premade function in Matlab that can gives sets of latitude and longitude of the shortest possible routes (like GPS) from one place to another (represented also as latitude longtitude)
So the *input* is:
Latitude and Longitude of a place A
Latitude and Longitude of a place B
The *output* is:
set of latitudes and longitudes of route 1 from A to B in a matrix
set of latitudes and longitudes of route 2 from A to B in a matrix
set of latitudes and longitudes of route 3 from A to B in a matrix
etc…..
The number of points of latitudes and longitudes in the output would depend on another input that describe how details the output would be.
Might be very complex things to do.
Thanks a lot in advance for any suggestion. Hi all,
Is there a premade function in Matlab that can gives sets of latitude and longitude of the shortest possible routes (like GPS) from one place to another (represented also as latitude longtitude)
So the *input* is:
Latitude and Longitude of a place A
Latitude and Longitude of a place B
The *output* is:
set of latitudes and longitudes of route 1 from A to B in a matrix
set of latitudes and longitudes of route 2 from A to B in a matrix
set of latitudes and longitudes of route 3 from A to B in a matrix
etc…..
The number of points of latitudes and longitudes in the output would depend on another input that describe how details the output would be.
Might be very complex things to do.
Thanks a lot in advance for any suggestion. gps, latitude, longitude MATLAB Answers — New Questions
MATLAB Function for Evaluating Body Position in SolidWorks Stuck in Busy Mode
I’m working on a MATLAB function that interacts with SolidWorks to evaluate the position of a body within a SolidWorks part. The function performs the evaluation correctly, but I’m encountering an issue where it gets stuck in a busy mode and doesn’t exit. This results in MATLAB becoming unresponsive indefinitely.
function position = getposition(path, bodyname, N)
% Connect to SolidWorks
% Crea un’istanza dell’applicazione SolidWorks
swApp = actxserver(‘SldWorks.Application’);
% Imposta l’applicazione SolidWorks come visibile
set(swApp, ‘Visible’, true);
% Apri il documento specificato
% ‘path’ deve essere il percorso completo del documento da aprire
swModel = invoke(swApp, ‘OpenDoc’, path, 1); % 1 per parti, 2 per assiemi, ecc.
% Ottieni il gestore delle configurazioni del modello aperto
configMgr = invoke(swModel, ‘ConfigurationManager’);
% Ottieni la configurazione attiva
config = invoke(configMgr, ‘ActiveConfiguration’);
% Ottieni i corpi solidi nella part
bodies = invoke(swModel, ‘GetBodies2’, 0, true); % 0 per corpi solidi
% swModel = [];
numBodies = length(bodies);
if bodyname == "Grain"
if N > 1
if mod(N, 2) == 0
bodyname = ["Grain_rep["+num2str(N/2)+"]","Grain_rep["+num2str(N/2+1)+"]"];
else
bodyname = "Grain_rep["+num2str(round(N/2))+"]";
end
end
end
position = zeros(length(bodyname),3);
j = 1;
% Loop through each body and get its name
for i = 1:numBodies
body = bodies{i}; % SolidWorks uses 0-based indexing
if length(bodyname)>1
if contains(body.Name, bodyname)
boundingBox = invoke(body, ‘GetBodyBox’);
position(j,:) = [mean([boundingBox(1:3); boundingBox(4:6)])];
j = j+1;
end
else
if body.Name == bodyname
boundingBox = invoke(body, ‘GetBodyBox’);
position = mean([boundingBox(1:3); boundingBox(4:6)]);
break
end
end
bodies{i} = [];
end
position = position.*[-1 1 1];
release(swApp)
release(swModel)
end
Despite checking for any infinite loops or blocking calls, I haven’t been able to identify the cause of the issue.
Has anyone faced a similar problem or can suggest a potential solution?
Thank you in advance for your assistance!I’m working on a MATLAB function that interacts with SolidWorks to evaluate the position of a body within a SolidWorks part. The function performs the evaluation correctly, but I’m encountering an issue where it gets stuck in a busy mode and doesn’t exit. This results in MATLAB becoming unresponsive indefinitely.
function position = getposition(path, bodyname, N)
% Connect to SolidWorks
% Crea un’istanza dell’applicazione SolidWorks
swApp = actxserver(‘SldWorks.Application’);
% Imposta l’applicazione SolidWorks come visibile
set(swApp, ‘Visible’, true);
% Apri il documento specificato
% ‘path’ deve essere il percorso completo del documento da aprire
swModel = invoke(swApp, ‘OpenDoc’, path, 1); % 1 per parti, 2 per assiemi, ecc.
% Ottieni il gestore delle configurazioni del modello aperto
configMgr = invoke(swModel, ‘ConfigurationManager’);
% Ottieni la configurazione attiva
config = invoke(configMgr, ‘ActiveConfiguration’);
% Ottieni i corpi solidi nella part
bodies = invoke(swModel, ‘GetBodies2’, 0, true); % 0 per corpi solidi
% swModel = [];
numBodies = length(bodies);
if bodyname == "Grain"
if N > 1
if mod(N, 2) == 0
bodyname = ["Grain_rep["+num2str(N/2)+"]","Grain_rep["+num2str(N/2+1)+"]"];
else
bodyname = "Grain_rep["+num2str(round(N/2))+"]";
end
end
end
position = zeros(length(bodyname),3);
j = 1;
% Loop through each body and get its name
for i = 1:numBodies
body = bodies{i}; % SolidWorks uses 0-based indexing
if length(bodyname)>1
if contains(body.Name, bodyname)
boundingBox = invoke(body, ‘GetBodyBox’);
position(j,:) = [mean([boundingBox(1:3); boundingBox(4:6)])];
j = j+1;
end
else
if body.Name == bodyname
boundingBox = invoke(body, ‘GetBodyBox’);
position = mean([boundingBox(1:3); boundingBox(4:6)]);
break
end
end
bodies{i} = [];
end
position = position.*[-1 1 1];
release(swApp)
release(swModel)
end
Despite checking for any infinite loops or blocking calls, I haven’t been able to identify the cause of the issue.
Has anyone faced a similar problem or can suggest a potential solution?
Thank you in advance for your assistance! I’m working on a MATLAB function that interacts with SolidWorks to evaluate the position of a body within a SolidWorks part. The function performs the evaluation correctly, but I’m encountering an issue where it gets stuck in a busy mode and doesn’t exit. This results in MATLAB becoming unresponsive indefinitely.
function position = getposition(path, bodyname, N)
% Connect to SolidWorks
% Crea un’istanza dell’applicazione SolidWorks
swApp = actxserver(‘SldWorks.Application’);
% Imposta l’applicazione SolidWorks come visibile
set(swApp, ‘Visible’, true);
% Apri il documento specificato
% ‘path’ deve essere il percorso completo del documento da aprire
swModel = invoke(swApp, ‘OpenDoc’, path, 1); % 1 per parti, 2 per assiemi, ecc.
% Ottieni il gestore delle configurazioni del modello aperto
configMgr = invoke(swModel, ‘ConfigurationManager’);
% Ottieni la configurazione attiva
config = invoke(configMgr, ‘ActiveConfiguration’);
% Ottieni i corpi solidi nella part
bodies = invoke(swModel, ‘GetBodies2’, 0, true); % 0 per corpi solidi
% swModel = [];
numBodies = length(bodies);
if bodyname == "Grain"
if N > 1
if mod(N, 2) == 0
bodyname = ["Grain_rep["+num2str(N/2)+"]","Grain_rep["+num2str(N/2+1)+"]"];
else
bodyname = "Grain_rep["+num2str(round(N/2))+"]";
end
end
end
position = zeros(length(bodyname),3);
j = 1;
% Loop through each body and get its name
for i = 1:numBodies
body = bodies{i}; % SolidWorks uses 0-based indexing
if length(bodyname)>1
if contains(body.Name, bodyname)
boundingBox = invoke(body, ‘GetBodyBox’);
position(j,:) = [mean([boundingBox(1:3); boundingBox(4:6)])];
j = j+1;
end
else
if body.Name == bodyname
boundingBox = invoke(body, ‘GetBodyBox’);
position = mean([boundingBox(1:3); boundingBox(4:6)]);
break
end
end
bodies{i} = [];
end
position = position.*[-1 1 1];
release(swApp)
release(swModel)
end
Despite checking for any infinite loops or blocking calls, I haven’t been able to identify the cause of the issue.
Has anyone faced a similar problem or can suggest a potential solution?
Thank you in advance for your assistance! solidworks, stuck MATLAB Answers — New Questions
Standalone Executable starting C++ application
Hello, we are compiling a standalone matlab application with matlab 2022b which starts a C++ compiled application. The C++ executable is compiled with c++20 standard. However, starting the application crashes using a c++20 function. With the process explorer we see that the dlls from the Matlab folder are loaded which are not compatible to c++20. What can we do?Hello, we are compiling a standalone matlab application with matlab 2022b which starts a C++ compiled application. The C++ executable is compiled with c++20 standard. However, starting the application crashes using a c++20 function. With the process explorer we see that the dlls from the Matlab folder are loaded which are not compatible to c++20. What can we do? Hello, we are compiling a standalone matlab application with matlab 2022b which starts a C++ compiled application. The C++ executable is compiled with c++20 standard. However, starting the application crashes using a c++20 function. With the process explorer we see that the dlls from the Matlab folder are loaded which are not compatible to c++20. What can we do? c++ dlls wrongly loaded MATLAB Answers — New Questions
How to resolve “Out of Tolerance” in the Simulation Data Inspector?
Hello,
Im comparing results of same TestCase between 2 different Matlab versions(2019 and 2021). My script outputs the Data Inspector HTML report which shows if there are differences between 2 TestCases. I’ve verified the comparision of 2 testcases has zero difference but the Max Diff Column in the Data Inspector shows values of 0.9,4,9 etc. for different signals.
I’ve loaded the File A and File B mat files in the data inspector and changed the global tolerance value to 0.1, 0.01,1 but that did not make any difference in the Out of Tolerance.
Can anyone provide suggestions for this ?
Thank you !Hello,
Im comparing results of same TestCase between 2 different Matlab versions(2019 and 2021). My script outputs the Data Inspector HTML report which shows if there are differences between 2 TestCases. I’ve verified the comparision of 2 testcases has zero difference but the Max Diff Column in the Data Inspector shows values of 0.9,4,9 etc. for different signals.
I’ve loaded the File A and File B mat files in the data inspector and changed the global tolerance value to 0.1, 0.01,1 but that did not make any difference in the Out of Tolerance.
Can anyone provide suggestions for this ?
Thank you ! Hello,
Im comparing results of same TestCase between 2 different Matlab versions(2019 and 2021). My script outputs the Data Inspector HTML report which shows if there are differences between 2 TestCases. I’ve verified the comparision of 2 testcases has zero difference but the Max Diff Column in the Data Inspector shows values of 0.9,4,9 etc. for different signals.
I’ve loaded the File A and File B mat files in the data inspector and changed the global tolerance value to 0.1, 0.01,1 but that did not make any difference in the Out of Tolerance.
Can anyone provide suggestions for this ?
Thank you ! data inspector, simulink, simulink data inspector MATLAB Answers — New Questions
After running Polyspace (Code Prover), in the “Reasons for Unchecked Code” section, if the progress of the “code operations” is not 100%, I would like to know how the percenta
After running Polyspace (Code Prover), in the "Reasons for Unchecked Code" section, if the progress of the "code operations" is not 100%, I would like to know how the percentage of "code operations" is calculated and what specifically "code operations" refer to.After running Polyspace (Code Prover), in the "Reasons for Unchecked Code" section, if the progress of the "code operations" is not 100%, I would like to know how the percentage of "code operations" is calculated and what specifically "code operations" refer to. After running Polyspace (Code Prover), in the "Reasons for Unchecked Code" section, if the progress of the "code operations" is not 100%, I would like to know how the percentage of "code operations" is calculated and what specifically "code operations" refer to. polyspace, matlab, code prover, reasons for unchecked code, code operations MATLAB Answers — New Questions
How can I deploy a standalone app for obtain data in real time from simulink
I create a simulink file for obtaining data from joystick, then I create an app in appdesigner to show data. In appdesigner I am using set_param() to set time simulation and get_param() to get data from output port in simulink when simulink is running that is the reason why I am using get_param() instead of sim function to run simulink. My app operates well . But afte I deploy a standalone desktop app for my project, when I test it comeout this error: Unsupported command in deployed mode: set_param.
I find that this function is not supported follow this link: https://www.mathworks.com/help/compiler/unsupported-functions.html
Have any another way to help me get data in real time from simulink and I can deploy a standalone app for using in another pc?
I am looking forward to hearing from you.
Thank youI create a simulink file for obtaining data from joystick, then I create an app in appdesigner to show data. In appdesigner I am using set_param() to set time simulation and get_param() to get data from output port in simulink when simulink is running that is the reason why I am using get_param() instead of sim function to run simulink. My app operates well . But afte I deploy a standalone desktop app for my project, when I test it comeout this error: Unsupported command in deployed mode: set_param.
I find that this function is not supported follow this link: https://www.mathworks.com/help/compiler/unsupported-functions.html
Have any another way to help me get data in real time from simulink and I can deploy a standalone app for using in another pc?
I am looking forward to hearing from you.
Thank you I create a simulink file for obtaining data from joystick, then I create an app in appdesigner to show data. In appdesigner I am using set_param() to set time simulation and get_param() to get data from output port in simulink when simulink is running that is the reason why I am using get_param() instead of sim function to run simulink. My app operates well . But afte I deploy a standalone desktop app for my project, when I test it comeout this error: Unsupported command in deployed mode: set_param.
I find that this function is not supported follow this link: https://www.mathworks.com/help/compiler/unsupported-functions.html
Have any another way to help me get data in real time from simulink and I can deploy a standalone app for using in another pc?
I am looking forward to hearing from you.
Thank you #standalone app #set_param, #simulink #get_param MATLAB Answers — New Questions
Run UDP as Simulator for OFDM TX/RX
I tried to run the Simulate portion of https://www.mathworks.com/help/soc/ug/OFDMTransmitandReceiveUsingXilinxRFSoCDevice.html.
I opened both soc_OFDM_top.slx and soc_OFDM_hostUDPReceive.slx and ran both of them. However, the constellation scope in soc_OFDM_hostUDPReceive.slx does not show anything.
How can I fix it? Thank you very much.I tried to run the Simulate portion of https://www.mathworks.com/help/soc/ug/OFDMTransmitandReceiveUsingXilinxRFSoCDevice.html.
I opened both soc_OFDM_top.slx and soc_OFDM_hostUDPReceive.slx and ran both of them. However, the constellation scope in soc_OFDM_hostUDPReceive.slx does not show anything.
How can I fix it? Thank you very much. I tried to run the Simulate portion of https://www.mathworks.com/help/soc/ug/OFDMTransmitandReceiveUsingXilinxRFSoCDevice.html.
I opened both soc_OFDM_top.slx and soc_OFDM_hostUDPReceive.slx and ran both of them. However, the constellation scope in soc_OFDM_hostUDPReceive.slx does not show anything.
How can I fix it? Thank you very much. udp, simulink, ofdm MATLAB Answers — New Questions
How to delete a line from UIAxes using plotedit in the menu bar with app designer.
Hi,
I want to edit a line from UIAxes using plotedit in the menu bar with app designer. I used callback "Plot_editMenuSelected" But it is not working.
function Plot_editMenuSelected(app, event)
plotedit(app.UIAxes,’on’)
end
Can someone please tell me solution?
ThanksHi,
I want to edit a line from UIAxes using plotedit in the menu bar with app designer. I used callback "Plot_editMenuSelected" But it is not working.
function Plot_editMenuSelected(app, event)
plotedit(app.UIAxes,’on’)
end
Can someone please tell me solution?
Thanks Hi,
I want to edit a line from UIAxes using plotedit in the menu bar with app designer. I used callback "Plot_editMenuSelected" But it is not working.
function Plot_editMenuSelected(app, event)
plotedit(app.UIAxes,’on’)
end
Can someone please tell me solution?
Thanks app designer, plotedit, uiaxes, menu MATLAB Answers — New Questions
Export Simscape to FMU
Hi,
I am currently trying to export a Simscape Model to FMU.
If this Model as schown in the picture without Connection Port can als FMU export.
Could the Connection port be used as a second output? I also can’t find any paper about this. Thanks a lot.
Best regards
SophiaHi,
I am currently trying to export a Simscape Model to FMU.
If this Model as schown in the picture without Connection Port can als FMU export.
Could the Connection port be used as a second output? I also can’t find any paper about this. Thanks a lot.
Best regards
Sophia Hi,
I am currently trying to export a Simscape Model to FMU.
If this Model as schown in the picture without Connection Port can als FMU export.
Could the Connection port be used as a second output? I also can’t find any paper about this. Thanks a lot.
Best regards
Sophia simscape, fmu MATLAB Answers — New Questions
Error installing Communication Toolbox Support Package for USRP Radio on offline Linux machine
I am trying to connect an N210 SDR to a computer running RHEL 8.2 and Matlab R2021b offline. This computer already has UHD installed. My online computer is running Windows and R2024a. I downloaded Support Software Downloader for win64 and downloaded the Communication Toolbox Support Package for USRP Radio for R2021b and moved the folder to the offline machine. I followed the intructions on the readme.txt and tried the interactive installation but I encountered an error that it failed to install the UHD Precompiled Library. Afterwards, the communications toolbox suppport package shows in the add-on manager but I am not able to configure the USRP and if I try to define a comm.SDRuReceiver I get an error that Matlab is unable to resolve the name. I tried removing the toolbox and reinstalling with the Silent Installation and don’t receive any errors, but the outcome is the same (can’t configure USRP and can’t resolve the name).
How can I fix this error? Is there a specific location that Matlab is looking for UHD to be installed at?I am trying to connect an N210 SDR to a computer running RHEL 8.2 and Matlab R2021b offline. This computer already has UHD installed. My online computer is running Windows and R2024a. I downloaded Support Software Downloader for win64 and downloaded the Communication Toolbox Support Package for USRP Radio for R2021b and moved the folder to the offline machine. I followed the intructions on the readme.txt and tried the interactive installation but I encountered an error that it failed to install the UHD Precompiled Library. Afterwards, the communications toolbox suppport package shows in the add-on manager but I am not able to configure the USRP and if I try to define a comm.SDRuReceiver I get an error that Matlab is unable to resolve the name. I tried removing the toolbox and reinstalling with the Silent Installation and don’t receive any errors, but the outcome is the same (can’t configure USRP and can’t resolve the name).
How can I fix this error? Is there a specific location that Matlab is looking for UHD to be installed at? I am trying to connect an N210 SDR to a computer running RHEL 8.2 and Matlab R2021b offline. This computer already has UHD installed. My online computer is running Windows and R2024a. I downloaded Support Software Downloader for win64 and downloaded the Communication Toolbox Support Package for USRP Radio for R2021b and moved the folder to the offline machine. I followed the intructions on the readme.txt and tried the interactive installation but I encountered an error that it failed to install the UHD Precompiled Library. Afterwards, the communications toolbox suppport package shows in the add-on manager but I am not able to configure the USRP and if I try to define a comm.SDRuReceiver I get an error that Matlab is unable to resolve the name. I tried removing the toolbox and reinstalling with the Silent Installation and don’t receive any errors, but the outcome is the same (can’t configure USRP and can’t resolve the name).
How can I fix this error? Is there a specific location that Matlab is looking for UHD to be installed at? usrp, uhd, offline, matlab, linux MATLAB Answers — New Questions
Nesting tiledlayouts within another tiledlayout
I would like to created a tiledlayout and, within each of the tiles, start another tiledlayout. I assume this kind of nesting is possible since, in the documentation for TiledChartLayout objects, it says that the parent of a TiledChartLayout can be another TiledChartLayout. However, the following example fails to produce the desired nesting. Instead of nesting the second sub-layout in the second tile, it tries to put it in the first tile. Is it possible to do what I am trying to do? If not, under what circumstances does it make sense to parent a TiledChartLayout to another TiledChartLayout.
m1=[5,6];
m2=[1,1,1,2];
T=tiledlayout(3,1); %Outer layout
nexttile(T,[1,1]); axis off %Next outer tile
t=tiledlayout(T,1,2); %first inner layout
for i=1:2
nexttile(t);
plot(rand(5,m1(i)));
legend(‘Location’,’southoutside’)
end
nexttile(T,[2,1]); axis off %Next outer tile
t=tiledlayout(T,2,2); %second inner layout
for i=1:4
nexttile(t);
plot(rand(5,m2(i)));
legend(‘Location’,’southoutside’)
endI would like to created a tiledlayout and, within each of the tiles, start another tiledlayout. I assume this kind of nesting is possible since, in the documentation for TiledChartLayout objects, it says that the parent of a TiledChartLayout can be another TiledChartLayout. However, the following example fails to produce the desired nesting. Instead of nesting the second sub-layout in the second tile, it tries to put it in the first tile. Is it possible to do what I am trying to do? If not, under what circumstances does it make sense to parent a TiledChartLayout to another TiledChartLayout.
m1=[5,6];
m2=[1,1,1,2];
T=tiledlayout(3,1); %Outer layout
nexttile(T,[1,1]); axis off %Next outer tile
t=tiledlayout(T,1,2); %first inner layout
for i=1:2
nexttile(t);
plot(rand(5,m1(i)));
legend(‘Location’,’southoutside’)
end
nexttile(T,[2,1]); axis off %Next outer tile
t=tiledlayout(T,2,2); %second inner layout
for i=1:4
nexttile(t);
plot(rand(5,m2(i)));
legend(‘Location’,’southoutside’)
end I would like to created a tiledlayout and, within each of the tiles, start another tiledlayout. I assume this kind of nesting is possible since, in the documentation for TiledChartLayout objects, it says that the parent of a TiledChartLayout can be another TiledChartLayout. However, the following example fails to produce the desired nesting. Instead of nesting the second sub-layout in the second tile, it tries to put it in the first tile. Is it possible to do what I am trying to do? If not, under what circumstances does it make sense to parent a TiledChartLayout to another TiledChartLayout.
m1=[5,6];
m2=[1,1,1,2];
T=tiledlayout(3,1); %Outer layout
nexttile(T,[1,1]); axis off %Next outer tile
t=tiledlayout(T,1,2); %first inner layout
for i=1:2
nexttile(t);
plot(rand(5,m1(i)));
legend(‘Location’,’southoutside’)
end
nexttile(T,[2,1]); axis off %Next outer tile
t=tiledlayout(T,2,2); %second inner layout
for i=1:4
nexttile(t);
plot(rand(5,m2(i)));
legend(‘Location’,’southoutside’)
end tiledchartlayout, nesting, tiledlayout, nexttile MATLAB Answers — New Questions
training network plot accuracy intead of rmse
hello everyone
I am using LSTM for data prediction and I use trainNetwork for it but When I run my cde the training plot only plots rmse and I want to plot accuracy ?
Here is my layers and Option what sholud I do
numResponses = 1 ;
featureDimension =1;
numHiddenUnits =200;
layers = [ …
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer
];
maxepochs = 500;
miniBatchSize = 45 ;
options = trainingOptions(‘adam’, … %%adam
‘MaxEpochs’,maxepochs, …
‘GradientThreshold’,1, …
‘Shuffle’,’every-epoch’, …
‘ValidationData’,{XVal_ZaMir,YVal_ZaMir}, …
‘ValidationFrequency’,25,…
‘InitialLearnRate’,0.005, …
‘MiniBatchSize’,miniBatchSize, …
‘LearnRateSchedule’,’piecewise’, …
‘LearnRateDropPeriod’,50, …
‘LearnRateDropFactor’,0.1, …
‘Verbose’,1, …
‘Plots’,’training-progress’);hello everyone
I am using LSTM for data prediction and I use trainNetwork for it but When I run my cde the training plot only plots rmse and I want to plot accuracy ?
Here is my layers and Option what sholud I do
numResponses = 1 ;
featureDimension =1;
numHiddenUnits =200;
layers = [ …
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer
];
maxepochs = 500;
miniBatchSize = 45 ;
options = trainingOptions(‘adam’, … %%adam
‘MaxEpochs’,maxepochs, …
‘GradientThreshold’,1, …
‘Shuffle’,’every-epoch’, …
‘ValidationData’,{XVal_ZaMir,YVal_ZaMir}, …
‘ValidationFrequency’,25,…
‘InitialLearnRate’,0.005, …
‘MiniBatchSize’,miniBatchSize, …
‘LearnRateSchedule’,’piecewise’, …
‘LearnRateDropPeriod’,50, …
‘LearnRateDropFactor’,0.1, …
‘Verbose’,1, …
‘Plots’,’training-progress’); hello everyone
I am using LSTM for data prediction and I use trainNetwork for it but When I run my cde the training plot only plots rmse and I want to plot accuracy ?
Here is my layers and Option what sholud I do
numResponses = 1 ;
featureDimension =1;
numHiddenUnits =200;
layers = [ …
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer
];
maxepochs = 500;
miniBatchSize = 45 ;
options = trainingOptions(‘adam’, … %%adam
‘MaxEpochs’,maxepochs, …
‘GradientThreshold’,1, …
‘Shuffle’,’every-epoch’, …
‘ValidationData’,{XVal_ZaMir,YVal_ZaMir}, …
‘ValidationFrequency’,25,…
‘InitialLearnRate’,0.005, …
‘MiniBatchSize’,miniBatchSize, …
‘LearnRateSchedule’,’piecewise’, …
‘LearnRateDropPeriod’,50, …
‘LearnRateDropFactor’,0.1, …
‘Verbose’,1, …
‘Plots’,’training-progress’); lstm, trainnetwork MATLAB Answers — New Questions
using element in a vector imported from workspace in simulink
###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention.###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention. ###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention. matlab, simulink, vector MATLAB Answers — New Questions