I have two columns of data imported from excel in workspace labelled as "Sample 1". How can I take those columns and make a smooth graph? They are both 88 rows long with column 1 being my X values and column 2 being my Y values. Thank you!

 채택된 답변

Star Strider
Star Strider 2020년 4월 16일

0 개 추천

I have no idea what your data are, and I am not certain what defines ‘smooth’.
With that proviso, try this:
xq = linspace(min(Sample_1(:,1)), max(Sample_1(:,1)), numel(Sample_1(:,1))*10);
yq = interp1(Sample_1(:,1), Sample_1(:,2), xq', 'pchip');
figure
plot(Sample_1(:,1), Sample_1(:,2), 'xb')
hold on
plot(xq, yq, '-r')
hold off
grid
Experiment with the interp1 function 'method' arguments to get different results.
.

댓글 수: 6

Eric Yoshida
Eric Yoshida 2020년 4월 16일
Hmm I'm getting this error message "Error using min
Invalid data type. First argument must be numeric or logical."
Star Strider
Star Strider 2020년 4월 16일
Apparently, ‘Sample_1’ is not numeric. I need to know what it is to help.
Eric Yoshida
Eric Yoshida 2020년 4월 16일
The variable is called Samples106 with column 1 in the data set being labelled "strain" and column 2 being labelled "Column1". Both columns start with 0 and continue in an increasing, non-linear order for 88 rows. Is that what you are looking for or is it something else?
Star Strider
Star Strider 2020년 4월 16일
Something else. It could be a cell array, in which case it would require different indexing. The easiest way to solve this would be for you to attach it as a .mat file.
Eric Yoshida
Eric Yoshida 2020년 4월 16일
Hopefully this helps. Sorry for the confusion!
No worries!
The ‘y’ field (the one that matches your description) is a table. It requires a bit of code to get its data.
Experiment with this:
D = load('Graph data.mat');
y = D.y;
vx = y.Column1;
vy = y.strain;
mult = 0.25;
xq = linspace(min(vx), max(vx), numel(vx)*mult);
yq = interp1(vx, vy, xq', 'pchip');
figure
plot(vx, vy, 'xb')
hold on
plot(xq, yq, '-r')
hold off
grid
Change the value of ‘mult’ and the interp1 'method' (here, 'pchip') to get the result you want.
.

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

추가 답변 (0개)

카테고리

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

질문:

2020년 4월 15일

댓글:

2020년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by