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.
조회 수: 15 (최근 30일)
이전 댓글 표시
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
채택된 답변
Jasvin
2023년 2월 9일
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)));
추가 답변 (3개)
Dyuman Joshi
2023년 2월 9일
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
2023년 2월 9일
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
2023년 2월 9일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Decomposition에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!