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 Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by