Convert from linear to log scale and back again

57 views (last 30 days)
I have include some example data.
%fit curve
[xData, yData] = prepareCurveData(log10(plot_data.xdata), plot_data.ydata);
ft = fittype( 'poly1' );
[fitresult, gof] = fit( xData, yData, ft ); %fit model to data
sp1=plot(fitresult,xData,yData,'ob'); %plot
I have distance on the x-axis, and sound pressure level on the y-axis. The distances are originally in metres, but when I fit a best fit line, the equation I use needs them to be logged. My issue is that I want to convert the x-axis back to metres so it's in a readable format. In addition, I'd like this to be on a logarithmic scale.
I tried the following:
xticklabels({'','','100','','','','','1000'}) %re-label x ticks in metres
but the x-axis doesn't appear to be logged at all when I do this and the 1000m value disappears when I set the scale to log.

Answers (1)

Jon on 23 Nov 2021
I think you can get what you want using MATLAB's semilogx function
Louise Wilson
Louise Wilson on 25 Nov 2021
Yes that is definitely the output. That is why I included a few comments back, the screenshot of running the code and the resultant figure, so you could believe it. I will start a new question.

Sign in to comment.





Community Treasure Hunt

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

Start Hunting!