changing range of calculations

2 vues (au cours des 30 derniers jours)
Salwa Ben Mbarek
Salwa Ben Mbarek le 28 Mai 2021
Commenté : Walter Roberson le 29 Mai 2021
Hello,
I've tried to change the following program until m=5 , n=5, p=5 rather than 4 . The error that I find while changing the matrix n or m is : Dimensions of arrays being concatenated are not consistent . Can you help me please? Thanks a lot.
function Frequencia_Table = Frequencia(v,lx,ly,lz)
% Building the array of values
m = [zeros(5,1); repelem([1:4]',6,1)];
n = [0; repmat(repelem([1 2 0]',2,1),4,1); 1; 1; 2; 2];
p = [repmat([1;0],14,1); 1];
Freq = [m, n, p, nan(size(m,1),1)];
v=3.*1e8;
% Function handle
f = @(lx,lz,ly) v/2.*sqrt((m./lx).^2 + (n./ly).^2 + (p./lz).^2);
%Calculate Frequencies (lx = 2, ly = 3, lz = 4) --> Enter the lengths here
lx=2;
ly=3;
lz=4;
Freq(:,4) = f(lx,lz,ly);
% Create a table of the results
Frequencia_Table = table(Freq(:,1),Freq(:,2),Freq(:,3),Freq(:,4),'VariableNames',{'m','n','p','Frequencia'});
end

Réponses (1)

Walter Roberson
Walter Roberson le 29 Mai 2021
function Frequencia_Table = Frequencia(v,lx,ly,lz)
% Building the array of values
maxval = 5;
m = [zeros(5,1); repelem([1:maxval]',6,1)];
n = repmat([0;0;1;1;2;2], maxval+1, 1);
n = n(2:end);
p = repmat([1;0],(maxval+1)*3,1);
p = p(2:end);
Freq = [m, n, p, nan(size(m,1),1)];
v=3.*1e8;
% Function handle
f = @(lx,lz,ly) v/2.*sqrt((m./lx).^2 + (n./ly).^2 + (p./lz).^2);
%Calculate Frequencies (lx = 2, ly = 3, lz = 4) --> Enter the lengths here
lx=2;
ly=3;
lz=4;
Freq(:,4) = f(lx,lz,ly);
% Create a table of the results
Frequencia_Table = table(Freq(:,1),Freq(:,2),Freq(:,3),Freq(:,4),'VariableNames',{'m','n','p','Frequencia'});
end
  2 commentaires
Salwa Ben Mbarek
Salwa Ben Mbarek le 29 Mai 2021
Thank you very much Walter .
In fact, when I ran this second program, I don't find all combinaisons . The idea is I want all combinaisons of n,m,p changing from 0 to 5 (n=5, p=1, m=5, n=4, p=0, m=5, ....) ..Could you help me to do that?
Thanks
Walter Roberson
Walter Roberson le 29 Mai 2021
[N, M, P] = ndgrid(0:5);
combinations = [N(:), M(:), P(:)]
combinations = 216×3
0 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 0 1 0 1 1 0 2 1 0 3 1 0

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by