changing range of calculations

조회 수: 2 (최근 30일)
Salwa Ben Mbarek
Salwa Ben Mbarek 2021년 5월 28일
댓글: Walter Roberson 2021년 5월 29일
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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 29일
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
Salwa Ben Mbarek
Salwa Ben Mbarek 2021년 5월 29일
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 2021년 5월 29일
[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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by