I am struggling with letter b and keep getting this as an error. Variable b must be of size [1 1]. It is currently of size [3 4]. Check where the variable is assigned a value.
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Consider the array (row vector), matrix, and column vector below.
A = [11.3 25.4 -58.6 66.2 82.8 37.9 41.5 3.6 60.7 14.2]
B = [1.256 3.135 5.489 7.236; 8.457 2.236 -4.456 6.128; 0.236 7.458 8.569 9.745]
C = [2.23; 3.58; -5.69; 7.47; 8.23; 5.46; 0.19; -9.73; 1.28; 4.46]
a) Sort A in ascending order and then calculate log base 10 of each element.
b) Calculate log base 10 of each element in B and then find the maximum value for the entire matrix.
c) Round all values down and then calculate log base 10 of each element in C.
here is my code:
A = [11.3 25.4 -58.6 66.2 82.8 37.9 41.5 3.6 60.7 14.2]
B = [1.256 3.135 5.489 7.236; 8.457 2.236 -4.456 6.128; 0.236 7.458 8.569 9.745]
C = [2.23; 3.58; -5.69; 7.47; 8.23; 5.46; 1.19; -9.73; 1.28; 4.46]
% a) Sort A in ascending order and then calculate log base 10 of each element.
A = sort(A)
a = log10(A)
% b) Calculate log base 10 of each element in B and then find the maximum value.
b = log10(B)
B = max(B,[],'all')
% c) Round all values down and then calculate log base 10 of each element in C.
C = floor(C)
c = log10(C)
0 commentaires
Réponse acceptée
Jasvin
le 9 Fév 2023
Hi Monique,
You just have to reassign the output to b instead of B as you are doing in this case.
Also, here’s another way you can accomplish the same thing in one line,
b = max(max(log10(B)));
Plus de réponses (3)
Dyuman Joshi
le 9 Fév 2023
Variable b has been used to store the log10 values of B matrix and it has not been updated afterwards, You have used B instead b
%In this line of code
B = max(B,[],'all')
There are some negative elements in B (and A and C as well) and by definition the input to log should be a positive value. I would suggest you to clarify from your instructor what is to be done, but the function log() accepts negative values as well
B = [1.256 3.135 5.489 7.236; 8.457 2.236 -4.456 6.128; 0.236 7.458 8.569 9.745];
logB = log10(B);
b = max(logB,[],'all')
Sulaymon Eshkabilov
le 9 Fév 2023
One typo B instead of b in computing max of log10(B):
A = [11.3 25.4 -58.6 66.2 82.8 37.9 41.5 3.6 60.7 14.2];
B = [1.256 3.135 5.489 7.236; 8.457 2.236 -4.456 6.128; 0.236 7.458 8.569 9.745];
C = [2.23; 3.58; -5.69; 7.47; 8.23; 5.46; 0.19; -9.73; 1.28; 4.46];
% a) Sort A in ascending order and then calculate log base 10 of each element.
A = sort(A)
a = log10(A)
% b) Calculate log base 10 of each element in B and then find the maximum value.
b = log10(B)
B = max(b,[],'all')
% c) Round all values down and then calculate log base 10 of each element in C.
C = floor(C)
c = log10(C)
Sarthak
le 9 Fév 2023
According to the question (b) part, you need to find log10 of all the elements in the matrix. Since the size of B is [3 4], when you apply log10(B) and save it in variable b, the size of b will eventually be [3 4] only. The maximum element out of b will have a size of [1 1] or we can say it will be a scalar.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Decomposition 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!