how to debug the non-working of real() function?

16 次查看(过去 30 天)
I have a 51x51 complex matrix and I only need its real value components. I am using real() to it but the operation is not being done? What to do? I have tried two methods but neither of them is working for me:
Method 1-
sinr_los1=real(sinr_los1);
Method 2-
for i=1:length(xAxis)
for j=1:length(yAxis)
sinr_los1(i,j)=real(sinr_los1(i,j));
end
end
Kindly suggest something

回答(2 个)

Florian Bidaud
Florian Bidaud 2022-10-19
Hi,
I guess sinr_los1 is your matrix ? Could you share the inputs and the outputs ?
Because both solutions should work
M =
1.0000 + 5.0000i 2.0000 + 3.0000i
4.0000 + 1.0000i -1.0000 - 8.0000i
>> real(M)
ans =
1 2
4 -1
  9 个评论

请先登录,再进行评论。


John D'Errico
John D'Errico 2022-10-19
编辑:John D'Errico 2022-10-19
When you get an error, don't just tell us that something is not working. Tell us the error message. The COMPLETE, error message, thus everything in red.
Would yo go to your doctor, and tell the doctor that something is not working, but not give a hint as to where you hurt?
Would you bring your car to a mechanic, and tell them only that you think the car has a problem, but nothing more?
BE CLEAR! You have information. MATLAB gives it to you, in the form of an error message, even if you don't understand the message you got. So tell us. We cannot see into your computer.
Without that information, since what you write is indeed valid, I can only conclude that you have defined a function or variable with the name real as the most likely possibility. Try this:
which real -all
Is there something you have defined with that name? If so, then when you try to use the real function, it will not work properly. You need to rename your own version, as MATLAB will be confused as to which real function (or variable) it should be using.
  9 个评论
Torsten
Torsten 2022-10-19
编辑:Torsten 2022-10-19
Then you should search for a function you created with name "real.m" and rename it. It's not usual that the MATLAB function "real" doesn't work like it should.
John D'Errico
John D'Errico 2022-10-19
编辑:John D'Errico 2022-10-19
The issue is then apparently not with real, as you claimed. but with your use of surfc. So we are getting closer. (But you don't need meshgrid here.) And surfc won't care if the inputs are negative.
z = randn(51,51) + 1i*randn(51,51);
xAx = 0:.1:5;
yAx = 0:.1:5;
surfc(xAx,yAx,real(z))
As you can see, there is no problem in using real, with surfc, nor any need to use meshgrid. But you still need to give us enough information to diagnose the problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by