How can I solve the issue showing the error " Wrong use of the `max` data type is invalid". "The first argument must be a numeric or logical value" in matlab

3 vues (au cours des 30 derniers jours)
Hi, I'm trying to compute the MVDR algorithm with my reel data shred. I have a script fragment showing an error.
Indeed, the last section of my loop would be written like this `Fmvdr(jj) = abs(Mvdr_algo'.*w_scan)` with a goal to display a matrix. Unfortunately, the error shows up as `The assignment cannot be performed because the index on the left is not compatible with the size on the right.` and I tried to solve as follow `Fmvdr{jj} = abs(Mvdr_algo'.*w_scan)` displaying the data with set of cell. ` Fmax` showing this error `Wrong use of the max data type is invalid. The first argument must be a numeric or logical value`. . How can I solve this issue? Here my code and also my data:
signal_data = abs(signal(5000:6000));
nbr_mics = 1;
nbr_snap = 100;
thetas = 30*pi/180;
center_frequency = 18000;
c =3e8;
lamda = c/center_frequency;
d = 0.5*lamda;
Is = zeros(nbr_mics,1);
for n = 1:nbr_mics
Is(n) = exp(j*2*pi*(n-1)*d*sin(thetas)/lamda);
end
Rxx = (signal_data.'*(signal_data.')')/nbr_snap;
detaS = Is;
Mvdr_algo = ( inv(Rxx).*detaS.*inv(detaS'.*inv(Rxx).*detaS));
%Linear array
p = -pi/2:pi/180:pi/2;
for jj = 1:1:length(p)
w_scan = zeros(nbr_mics,1);
scan = p(jj);
for n = 1:1:nbr_mics
w_scan(n) = exp(j*2*pi*(n-1)*d*sin(scan)/lamda);
end
Fmvdr{jj} = abs(Mvdr_algo'.*w_scan);
end
% Figure
Fmax = max(max(Fmvdr)); %display error
Fa = Fmvdr/(Fmax);
Fa = 20*log10(Fa);
figure(1);
plot(180*p/pi,Fa,'b-')

Réponse acceptée

Steven Lord
Steven Lord le 25 Fév 2021
The max function is not defined for cell array inputs. If it were, what would you expect the result of max to be if called on the C variable below?
C = {1:10, single(magic(5)), @sin; {struct('foo', 1)}, figure, RandStream('mt19937ar')}
C = 2x3 cell array
{1×10 double} {5×5 single} { @sin} {1×1 cell } {1×1 Figure} {1×1 RandStream}
The output on the first two cells in the first row would be pretty straightforward to explain. But since a cell array can contain various types of data, including some that aren't numeric (everything in C except the first two cells in the first row, for example) it doesn't always make sense to ask for the max.
So what is the purpose of that line in the code?
  • Purpose 1: do you want the global maximum value among all the arrays in all the cells in Fmvdr?
  • Purpose 2: are you assuming all those arrays are the same size and want each element of the result to be the maximum among the corresponding elements of the contents of each cell in Fmvdr?
  • Purpose 3: ?
Using a for loop or cellfun to compute the max of each cell in Fmvdr then calling max to take the maximum of all those is one approach for Purpose 1.
Stacking the arrays into a higher dimensional array and calling max with a dimension input is one approach for Purpose 2.
A = {magic(4), randi(16, [4 4]), 6+gallery('minij', 4)};
celldisp(A)
A{1} = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A{2} = 13 4 16 7 11 10 3 12 1 9 4 9 7 8 4 7 A{3} = 7 7 7 7 7 8 8 8 7 8 9 9 7 8 9 10
B = cat(3, A{:})
B =
B(:,:,1) = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 B(:,:,2) = 13 4 16 7 11 10 3 12 1 9 4 9 7 8 4 7 B(:,:,3) = 7 7 7 7 7 8 8 8 7 8 9 9 7 8 9 10
max(B, [], 3)
ans = 4×4
16 7 16 13 11 11 10 12 9 9 9 12 7 14 15 10
  2 commentaires
Kounkou Vincent
Kounkou Vincent le 25 Fév 2021
@Steven Lord , thank you for replying. Fmvdr aims for the Orientation Failure spatiale. Once the calculation is performed, the matrix will be used to draw the directional diagram.First we will choose the maximum points in the matrix before drawing. I agreed on purpose 2 where all arrays have the same size and that the global maximum value of each array is considered. The cells option has been used to correct the error in Fmvdr, normally this is not my goal to display cells.I want them to be the same size . How to make the Fmvdr compute same size of arrays not cells when using Fmvdr(jj) =abs(Mvdr_algo'.*w_scan)? Because it displays an incompatible error when multiplying the Mvdr_algo and w_san matrices.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by