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

조회 수: 4 (최근 30일)
Abhishek Goyal
Abhishek Goyal 2022년 10월 19일
편집: John D'Errico 2022년 10월 19일
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
Torsten
Torsten 2022년 10월 19일
That's impossible.
Abhishek Goyal
Abhishek Goyal 2022년 10월 19일
Well, i don't know what to say but cuss my luck

댓글을 달려면 로그인하십시오.


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에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by