Quick question on understanding ./ notation
2 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
John D'Errico
2015-5-19
编辑:John D'Errico
2015-5-19
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 个评论
Stephen23
2015-5-19
Although the cyclist has already given this link, it deserves a bit more prominence:
更多回答(1 个)
the cyclist
2015-5-19
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!