Borrar filtros
Borrar filtros

I want to create an .exe file from a .m file. I get the following error message (see belove)

1 visualización (últimos 30 días)
Dear collegues,
I want to make an executable from a matlab code with the help of the Matlab compiler app. I get the following error:
"array have incompatible sizes for this operation at line "y = sqrt((2.*g_vec./(pi.*lambdaG) + 4.*sigma_vec./rho_vec.*(2.*pi./lambdaG.^3)).*tanh(2.*pi.*H_vec./lambdaG));
I think I did everything possible to get rid of the issue, but no, it doesn't work...
clear;
clc; clear all;
disp('f_0 is the driving frequency in [Hz],');
disp('g is the gravity acceleration in [m/s^2],');
disp('lambda is the capillary wavelength in [m],');
disp('sigma is the surface tension of the fluid in [N/m],');
disp('rho is the density of the fluid in [kg/m^3],');
disp('and H is the depth of the cuve in [m].');
prompt = "What is the value of g ? ";
g = input(prompt);
prompt = "What is the value of lambda ? ";
lambda = input(prompt);
prompt = "What is the value of sigma ? ";
sigma = input(prompt);
prompt = "What is the value of rho ? ";
rho = input(prompt);
prompt = "What is the value of H ? ";
H = input(prompt);
f_0 = sqrt((2.*g./(pi.*lambda) + 4.*sigma./rho.*(2.*pi./lambda.^3)).*tanh(2.*pi.*H./lambda));
fprintf('The value of f_0 is %d\n', f_0)
lambdaG = linspace(0, 0.2, 100);
g_vec = repmat(g, size(lambdaG));
sigma_vec = repmat(sigma, size(lambdaG));
rho_vec = repmat(rho, size(lambdaG));
H_vec = repmat(H, size(lambdaG));
pi_vec = repmat(pi, size(lambdaG));
f_1 = sqrt((2.*g_vec./(pi_vec.*lambdaG) + 4.*sigma_vec./rho_vec.*(2.*pi_vec./lambdaG.^3)).*tanh(2.*pi_vec.*H_vec./lambdaG));
semilogy(lambdaG,f_1)
xlabel('Distance between lines (=lambda/2) [m]')
ylabel('Driving frequency (f_0) [Hz]')
title('Dependence of the driving frequency on the distance between lines')
xlim([0 0.2])
ylim([0 5000])
  2 comentarios
Torsten
Torsten el 14 de En. de 2023
Editada: Torsten el 14 de En. de 2023
"array have incompatible sizes for this operation at line "y = sqrt((2.*g_vec./(pi.*lambdaG) + 4.*sigma_vec./rho_vec.*(2.*pi./lambdaG.^3)).*tanh(2.*pi.*H_vec./lambdaG));
The line
y = sqrt((2.*g_vec./(pi.*lambdaG) + 4.*sigma_vec./rho_vec.*(2.*pi./lambdaG.^3)).*tanh(2.*pi.*H_vec./lambdaG));
does not exist in the code you posted.
The code you posted works without problems:
clear;
clc; clear all;
disp('f_0 is the driving frequency in [Hz],');
f_0 is the driving frequency in [Hz],
disp('g is the gravity acceleration in [m/s^2],');
g is the gravity acceleration in [m/s^2],
disp('lambda is the capillary wavelength in [m],');
lambda is the capillary wavelength in [m],
disp('sigma is the surface tension of the fluid in [N/m],');
sigma is the surface tension of the fluid in [N/m],
disp('rho is the density of the fluid in [kg/m^3],');
rho is the density of the fluid in [kg/m^3],
disp('and H is the depth of the cuve in [m].');
and H is the depth of the cuve in [m].
%prompt = "What is the value of g ? ";
g = 9.81;%input(prompt);
%prompt = "What is the value of lambda ? ";
lambda = 1.0e-4;%input(prompt);
%prompt = "What is the value of sigma ? ";
sigma = 0.02;%input(prompt);
%prompt = "What is the value of rho ? ";
rho = 1000;%input(prompt);
%prompt = "What is the value of H ? ";
H = 3e1;%input(prompt);
f_0 = sqrt((2.*g./(pi.*lambda) + 4.*sigma./rho.*(2.*pi./lambda.^3)).*tanh(2.*pi.*H./lambda));
fprintf('The value of f_0 is %d\n', f_0)
The value of f_0 is 2.242136e+04
lambdaG = linspace(0, 0.2, 100);
g_vec = repmat(g, size(lambdaG));
sigma_vec = repmat(sigma, size(lambdaG));
rho_vec = repmat(rho, size(lambdaG));
H_vec = repmat(H, size(lambdaG));
pi_vec = repmat(pi, size(lambdaG));
f_1 = sqrt((2.*g_vec./(pi_vec.*lambdaG) + 4.*sigma_vec./rho_vec.*(2.*pi_vec./lambdaG.^3)).*tanh(2.*pi_vec.*H_vec./lambdaG));
semilogy(lambdaG,f_1)
xlabel('Distance between lines (=lambda/2) [m]')
ylabel('Driving frequency (f_0) [Hz]')
title('Dependence of the driving frequency on the distance between lines')
xlim([0 0.2])
ylim([0 5000])
Walter Roberson
Walter Roberson el 14 de En. de 2023
It is the case that the compiler does not support implicit expansion. It does however support scalar vector operations which is all that is needed by the code unless one of the inputs is nonscalar

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de En. de 2023
You do not need any of those repmat -- not unless some value that is input() is a non-scalar.
If the input() values are scalars then you have some ./ divisions by a vector, but the only implicit expansion you have is constant .* vector or constant ./ vector, and those are supported by the compiler.
The compiler does not (if I recall correctly) support general implicit expansion -- the kind of expansion that would say that a 3 x 1 vector .* a 1 x 2 vector should produce a 3 x 2 result.
  2 comentarios
Thierry Rebetez
Thierry Rebetez el 14 de En. de 2023
Dear Walter Thank you for your message. I u your reply correctly, but I don't really know what to change in the code in order that it works. Do you have any idea how to improve the code? Thank you very much

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by