Help changing axis direction with for loop plot.

Hello,
I am trying to graph data from excel with a for loop but I need to reverse and log my x axis. I figured out how to log the axis but trying to use set(gca,''XDir','reverse') does not work. It gives the error "Unable to use a value of type matlab.graphics.axis.Axes as an index.". Thanks for any advice. Here is also an example of what I'm looking to achieve as far as the axis is concerned.
data = xlsread('Field_Testing','GrainSize');
sz = size(data);
rows = sz(1);
colms = sz(2);
set1 = data(:,[1,2]);
c = {};
for j = 1:colms
if rem(j,2) == 0
set = data(:, [j-1, j]);
c{end+1} = set; %saves to end of each previous cell
end
end
figure()
for z = 1:(colms/2)
arr = c{z};
arr = rmmissing(arr);
x = arr(:,1);
y = arr(:,2);
p = semilogx(x,y);
set(gca,'XDir','reverse')
hold on
end
hold off

댓글 수: 3

Les Beckham
Les Beckham 2020년 4월 11일
편집: Les Beckham 2020년 4월 11일
I'm not real sure how you would go about creating a 'reverse' log axis. Perhaps you could plot 1/x and then manually set the axis tick labels.
I do know for certain that you should never ever name a variable 'set' (like you did here: set = data(:, [j-1, j]);). This is probably the most common function name in Matlab. Overriding it with a variable will almost certainly break a lot of things, including the graphics routines that you need to make any kind of plot.
Cody Arnold
Cody Arnold 2020년 4월 11일
편집: Cody Arnold 2020년 4월 11일
Oh ok, thanks for the tip I really appreciate it!
By reverse I mean I want the axis to plot in descending order. It should be in log scale as well but I already got that part with semilogx. Removing the vairable set seems to have fixed it! thanks again!
I'm glad that helped. As far as doing the 'reverse' log, you might try my idea of plotting 1/x instead of x and experiment to see if that gets you closer to what you want.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 4월 11일

댓글:

2020년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by