Quick question on understanding ./ notation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jesse
el 19 de Mayo de 2015
Comentada: Stephen23
el 19 de Mayo de 2015
Greetings all,
I have the following "snippet" of code:
Zeta_EM31_West = DrillHoleData2(:,3)/3.67;
%Line above outputs a 16x1 double array, I can provide "DrillHoleData2" if needed
Response_values_H= 0:0.01:9;
R_h=sqrt(4*Response_values_H.^2+1)-(2*Response_values_H);
R_h(Response_values_H>=9.1) = 0;
R_h_Case1A=interp1(Response_values_H,R_h,Zeta_EM31_West);
Now I'm a bit confused on something. Say the next line is this: sigma_2_Case1A=EM31CondMidSwathWest/R_h_Case1A;
where "EM31CondMidSwathWest" is another 16x1 array (and I can provide the numbers if needed). Now just using / will provide me with a 16x16 double, which I understand, but in one column I'll receive values, and the rest are zeros (I also understand this).
What I don't understand is if I say: sigma_2_Case1A=EM31CondMidSwathWest./R_h_Case1A;
which will be a 16x1 double, but the numbers will be different than those with using "/". Shouldn't they be the same?
Thanks! -J
1 comentario
Respuesta aceptada
John D'Errico
el 19 de Mayo de 2015
Editada: John D'Errico
el 19 de Mayo de 2015
If they should be the same for / and ./ I imagine they would not give us TWO different operators?
./ does an element-wise division. It divides each element by the corresponding element, as long as the two vectors/arrays are the same size and shape. It will fail if they are not, unless one of them was a scalar.
/ does the element-wise division IF the denominator is a scalar. If the two arguments are arrays, or vectors, then linear algebra comes into play.
B/A is equivalent to B*inv(A), WHEN A is a square matrix. If A is not a square matrix, then a solve is done that employs a factorization of the matrix A.
READ THE HELP. Of course, I admit that it might not be obvious to look at these:
help slash
help rdivide
help ldivide
help mrdivide
After all, I might have naively looked for help under divide. I honestly think it would be a good idea if this:
help divide
produced links to the appropriate functions, and explained the basic differences between all of those operators.
3 comentarios
Stephen23
el 19 de Mayo de 2015
Although the cyclist has already given this link, it deserves a bit more prominence:
Más respuestas (1)
the cyclist
el 19 de Mayo de 2015
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!