Cell-Matrix, I can't extract values

조회 수: 2 (최근 30일)
Paul Rogers
Paul Rogers 2021년 1월 10일
댓글: Star Strider 2021년 1월 10일
I have the figure in attached and I need to extract values.
I run this code:
F = openfig('phi_1.fig');
ax = gca;
lines = findobj(ax, 'Type','Line');
for k = 1:numel(lines)
x{1,:} = lines(k).XData;
y{k,:} = lines(k).YData;
end
the problem is that I don't get a vector, but a matrix with other matrix inside and I don't know how to extract the values.
For the x I don't have problems, I type:
time=cell2mat(x);
but for the y I don't know
  댓글 수: 1
Star Strider
Star Strider 2021년 1월 10일
See my Answer for a solution to that exact problem.

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

채택된 답변

Star Strider
Star Strider 2021년 1월 10일
Change the code slightly to:
F = openfig('phi_1.fig');
ax = gca;
lines = findobj(ax, 'Type','Line');
for k = 1:numel(lines)
x{k} = lines(k).XData; % Force Row Vector
y{k} = lines(k).YData; % Force Row Vector
end
xv = cell2mat(x); % Extract From Cell Array
yv = cell2mat(y); % Extract From Cell Array
[xvs,idx] = sort(xv); % Sort Ascending
yvs = yv(idx); % Sort According To ‘xvs’
figure
plot(xvs, yvs)
grid
That should do what you want.
  댓글 수: 3
Paul Rogers
Paul Rogers 2021년 1월 10일
sorry, it works great, I just recive the error sound and I goot consused, but it works great
Star Strider
Star Strider 2021년 1월 10일
No worries!
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by