how to debug the non-working of real() function?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (2)
Florian Bidaud
el 19 de Oct. de 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 comentarios
John D'Errico
el 19 de Oct. de 2022
Editada: John D'Errico
el 19 de Oct. de 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 comentarios
John D'Errico
el 19 de Oct. de 2022
Editada: John D'Errico
el 19 de Oct. de 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.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!