How to work rdivide function

4 Ansichten (letzte 30 Tage)
Andras Gergely
Andras Gergely am 8 Aug. 2019
Kommentiert: Stephen23 am 8 Aug. 2019
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 Kommentar
Stephen23
Stephen23 am 8 Aug. 2019
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 8 Aug. 2019
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.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 8 Aug. 2019
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.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by