How to work rdivide function

2 次查看(过去 30 天)
Hi Everone,
I have a question in relation to the rdivide function.
I tried to use the rdivide function with two arrays but the program only provided a resultant array without any vauable result, not even zeros!!
Please refer to the following what expression I used initially and after to circumvent the shortage of computation one by one of array elements:
R = rdivide(abs(i_min_1(1,1)),i_max_1(1,1));
It only worked by simple but very struggle way, piece by piece as it goes:
r_1=abs(i_min_1(1,1))/i_max_1(1,1);
Please let me know what could go wrong with it.
Many thanks in advance.
Andras
  1 个评论
Stephen23
Stephen23 2019-8-8
Andras Gergely's incorrectly accepted "Answer" moved here:
Dear Walter Robinson and John D'Errico,
Now it works but anyway I cannot comprehend why yesterday it would not work despite I refered to and checked with the inbuilt help function.
Sorry for the inappropriate postage.
Best wishes,
Andras

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2019-8-8
Please don't post answers to questions as you did to another question when you just want to ask a question.
Regardless, it looks like your question (confusing as it is) asks how to divide the elements of two arrays.
Use the ./ operator to do this.
A = rand(10);
B = rand(10);
C = A./B;
that is, if you want to operate in an element-wise way on two arrrays, then use the operators ./ and .* and .^ for that. Similarly, if you want to compute the reciprocal of all elements of a vector:
x = 1:10;
reciprocalx = 1./x;
The / and * and ^ operators are used for matrix algebra, not for simple element-wise operations.
But really, if you are asking questions like this, you need to read the getting started tutorials in MATLAB.

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-8-8
With the exception of the case where the numerator or denominator are scalars, rdivide() before R2016b requires that the numerator and the denominator are exactly the same size. As of R2016b, rdivide() instead requires that the numerator and denominator are "compatible" sizes, as-if you had done bsxfun(@rdivide, Numerator, Denominator) . So for example if the numerator were 5 x 7 and the denominator were 5 x 1, then that would be considered compatible because it the 5 x 1 denominator would get implicitly extended to 5 x 7.
The situation is different for the function mrdivide(), which does not require that the numerator and denominator are exactly the same size or are compatible sizes, and instead requires that the numerator and denominator have the same number of columns.
Note that rdivide() is the formal name of the ./ function for element-by-element division, and that mrdivide() is the formal name for the / function for solving systems of linear equations.

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by