how to debug the non-working of real() function?
Show older comments
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
Answers (2)
Florian Bidaud
on 19 Oct 2022
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 Comments
Abhishek Goyal
on 19 Oct 2022
Torsten
on 19 Oct 2022
As said, the reason must be your matrix "sinr_los1". So we need it here or at least the output when you type
class(sinr_los1)
size(sinr_los1)
Abhishek Goyal
on 19 Oct 2022
And what do you get when you type
sinr_los1=real(sinr_los1);
?
The original complex matrix "sinr_los1" ?
Maybe - as John D'Errico said - you defined a function with name "real" ? Then you will have to rename it.
Florian Bidaud
on 19 Oct 2022
And what is the following code returning ?
real(sinr_los1)
At least can you explain what is it doing so we can help you
Abhishek Goyal
on 19 Oct 2022
Abhishek Goyal
on 19 Oct 2022
Torsten
on 19 Oct 2022
That's impossible.
Abhishek Goyal
on 19 Oct 2022
John D'Errico
on 19 Oct 2022
Edited: John D'Errico
on 19 Oct 2022
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 Comments
Abhishek Goyal
on 19 Oct 2022
You know that you first have to use "meshgrid" on the arrays "xAxis" and "yAxis" before you can use them for "surfc" ?
[XAXIS,YAXIS] = meshgrid(xAxis,yAxis);
surfc(XAXIS,YAXIS,(sinr_los1+conj(sinr_los1))/2)
Abhishek Goyal
on 19 Oct 2022
You wrote you use
surfc(xAxis, yAxis, sinr_los1)
with xAxis, yAxis being arrays of size 51. But they are matrices of size 51x51, aren't they ?
And what if you use the above code ?
(sinr_los1+conj(sinr_los1))/2
instead of
real(sinr_los1)
?
Abhishek Goyal
on 19 Oct 2022
Torsten
on 19 Oct 2022
What did you change ?
Abhishek Goyal
on 19 Oct 2022
John D'Errico
on 19 Oct 2022
Edited: John D'Errico
on 19 Oct 2022
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.
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!