How to get xticklabels from xticks by merging cells?
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
Dear all,
I want to get my ticklabels from an array of numbers.
As the function  is taking a cell-array, I want to create a function
 is taking a cell-array, I want to create a function  which enables the conversion of my array of numbers
 which enables the conversion of my array of numbers  into a cell
 into a cell  :
:
 is taking a cell-array, I want to create a function
 is taking a cell-array, I want to create a function  which enables the conversion of my array of numbers
 which enables the conversion of my array of numbers  into a cell
 into a cell  :
:Xticks = [1,2,3];
Xtickslabels = tick2ticklabel(Xticks)
>>> Xtickslabels = {'1','2','3'}
I tried this:
Xticks = [1,2,3];
tmp = split(num2str(Xticks))
tmp = reshape(tmp,1,length(tmp))
But I am stuck here as I didn't find a way to merge the cells into one.
Thanks in advance.
Best regards,
louis
0 个评论
采纳的回答
  Chunru
      
      
 2022-8-24
        plot(randn(7,1))
Xticks = 1:2:7;         % for example
% It's simpler and neater to use string 
Xtickslabels = string(Xticks)
set(gca, 'XTick', Xticks, 'XTickLabel', Xtickslabels)
0 个评论
更多回答(2 个)
  Mathieu NOE
      
 2022-8-24
        hello 
here you are my friend : 
Xticks = [1,2,3];
tmp = num2str(Xticks);
Xtickslabels{1} = tmp;
0 个评论
  Louis Tomczyk
 2022-8-24
        2 个评论
  Mathieu NOE
      
 2022-8-24
				hello again 
Xticklabels must not be a 1 x 1 cell but a 1 x 20 cell
making all this code for 1 x 1 cell is unneccessary
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





