- 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: ?
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)
Afficher commentaires plus anciens
Kounkou Vincent
le 25 Fév 2021
Commenté : Kounkou Vincent
le 25 Fév 2021
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-')
0 commentaires
Réponse acceptée
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')}
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?
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)
B = cat(3, A{:})
max(B, [], 3)
2 commentaires
Plus de réponses (0)
Voir également
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!