フィルターのクリア

Displaying an axis scale in mm rather than pixels

17 ビュー (過去 30 日間)
Robbie McDermott
Robbie McDermott 2017 年 11 月 1 日
コメント済み: elvis okacha 2019 年 4 月 13 日
I have written a code for image analysis that uses the number of pixels throughout to calculate lengths. Now I want to plot graphs and have my axis reading in millimetres rather than number of pixels. I have a calibration factor calculated, is there a simple way I can have axis in millimetres. I need this code to work for multiple pictures therefore using the xticks and xticklabels method would help.

採用された回答

Looky
Looky 2017 年 11 月 1 日
編集済み: Looky 2017 年 11 月 1 日
It's a bit tricky without any example data, but this should do the trick.
conversion=0.1; % in mm/pixel
addMM=@(x) sprintf('%.3fmm',x*conversion);
xticklabels(cellfun(addMM,num2cell(xticks'),'UniformOutput',false));
yticklabels(cellfun(addMM,num2cell(yticks'),'UniformOutput',false));
You can fine tune how many digits are displayed by editing the '%.3fmm' in the second line(see formatSpec). Change the variable conversion to your needs. It's in mm per pixel. Hope that helps, if not, just ask. Note that Matlab still treats the axis in Pixel, but displays the converted mm. If you make changes to xtick and ytick, you have to call the above lines again.
  2 件のコメント
Robbie McDermott
Robbie McDermott 2017 年 11 月 2 日
That is fantastic, does exactly what I wanted it to! Thank you, saved me two week work!
Stelios Fanourakis
Stelios Fanourakis 2019 年 1 月 9 日
It is a very nice solution, indeed. Thanks a lot as well. I'd like to ask whether there is a way to have more steps, like every 50 mm or every 10 mm, instead of almost a 100 mm

サインインしてコメントする。

その他の回答 (2 件)

elvis okacha
elvis okacha 2019 年 4 月 10 日
Look I'm trying to implement your solution within a button program in my guitar,but I still get error that 'undefined variable 'xticks''.allitle new to Matias.is there some additional code on the use of stick and xticklabels?kindly
  9 件のコメント
Walter Roberson
Walter Roberson 2019 年 4 月 12 日
set() the axes XTickLabels and YTickLabels properties instead of calling xticklabels() and yticklabels()
elvis okacha
elvis okacha 2019 年 4 月 13 日
Ok thanks

サインインしてコメントする。


elvis okacha
elvis okacha 2019 年 4 月 10 日
Sorry.'looky' not 'look'

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by