I currently need to input xlsx data into matlab to a precision of 7 decimal places, and then interpolate data inbetween those points. However, I'm relatively sure that the data is only being inputted to 4 decimal places, as the interp1 function is giving back the error: "The grid vectors must contain unique points" (it uses griddedInterpolant to solve the answer). This would happen if the program is rounding to 4 decimals, as I have some data that is 0.0000100, 0.0000106, etc.. Everything I see online, though, says that MATLab imports up to 15 decimal places. Is there something else that could be wrong here?
(Additionally, I have the format set to long)
Thanks.

댓글 수: 6

Adam Danz
Adam Danz 2020년 7월 29일
Have you confirmed that your raw data are all unique points?
Could you attach a mat file containing the imported variable?
Emily Barber
Emily Barber 2020년 7월 29일
I have not, and great point. The output is somewhat sinusoidal, so it is likely that there are repeats there as I originally broke up the points into output and input. I found a way online to do the 'unique' function for a 2-column (input and output) matrix, which remved some points, but after that point I had to break it into 2 seperate arrays (input and output) in order to complete the interpolate function. At this point, there are some repeats in just the output function, which may be causng the problem.
I've attached the raw data as an xlsx. The mat didn't seem to fit, even when zipped.
The code I used for this purpose. I believe I included all variables in this shortened version but if not, they are all present in the total code
EElas=xlsread('U238Elastic'); % Read in data
nRow = size(EElas, 1); % Removes any not-unique 2D points
c = cell(1, nRow);
for iRow = 1:nRow
c{iRow} = unique(EElas(iRow, :), 'stable');
end
EE = cat(1, c{:});
EElasInput=EE(:,1); % Seperates out into inputs and outputs
EElasOutput=EE(:,2);
E1=10^6
wElas=ismember(E1,EElasInput); % If it's already a point, no need to interpolate
if wElas==1
v=find(EElasInput==E1);
SigEl=EElasOutput(v);
else % If not, try interpolating
SigEl=interp1(EElasInput,EElasOutput,E1)*10^-28; % The error occurs in this line
if isnan(SigEl) % If it still doesn't work, extrapolate
SigEl=interp1(EElasInput,EElasOutput,E1,'linear','extrap')*10^-28;
end
end
Adam Danz
Adam Danz 2020년 7월 29일
편집: Adam Danz 2020년 7월 29일
Clearly the xlsread output is greater than 4dp precision
format long
>> EElas(1:10,:)
ans =
0.000010000000000 35.397709999999996
0.000010625000000 34.404020000000003
0.000011250000000 33.496060000000000
0.000011875000000 32.662320000000001
0.000012500000000 31.893370000000001
0.000013750000000 30.519690000000001
0.000015000000000 29.325990000000001
0.000016250000000 28.276740000000000
0.000017500000000 27.345490000000002
0.000018750000000 26.512090000000001
I don't understand the point of the iRow loop. If any of the rows contained duplicate values, the code would break just after the loop when you contatenate the "c" values since at least one cell would only contain 1 value.
I haven't looked too deeply at the rest of the code but I ran it and it does not produce an error. So I'm a but lost as to how I can help. My answer was written before seeing your updated code so my answer may not be entirely relevant. However, I do recommend using readmatrix instead of xlsread.
Emily Barber
Emily Barber 2020년 7월 29일
I copied exactly what I sent you into a function and it worked, which means that something's likely wrong with my code as a whole (as it didn't work once placed in the function). I'll try to keep working with it, thank you for your help.
Adam Danz
Adam Danz 2020년 7월 29일
Feel free to continue to discussion if you find the source the problem and have trouble fixing it. If the problem is greatly different from the conversation so far, it would be better to start a new question and you can provide a link to it here in the comment section if you'd like.

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

 채택된 답변

Adam Danz
Adam Danz 2020년 7월 29일
편집: Adam Danz 2020년 7월 29일

0 개 추천

Thanks for providing the raw data.
I'm not seeing what you're seeing. My data exporation steps are below.
% Read-in the data
x = readmatrix('U238Elastic.xlsx');
% Check out the first few rows
x(1:10,:)
% RESULT (format: shortg)
% ans =
% 1e-05 35.398
% 1.0625e-05 34.404
% 1.125e-05 33.496
% 1.1875e-05 32.662
% 1.25e-05 31.893
% 1.375e-05 30.52
% 1.5e-05 29.326
% 1.625e-05 28.277
% 1.75e-05 27.345
% 1.875e-05 26.512
Clearly the precision is greater than 4dp.
Are there any duplicate rows?
% Produce index of unique rows of x
[~, unqIdx] = unique(x,'rows');
isUnq = ismember(1:size(x,1), unqIdx);
% Compute the percentage of rows that are unique
percentUnq = sum(isUnq)/size(x,1)*100
% RESULT
% percentUnq =
% 100
It seems that all of the coordinates are unique. Maybe you're reading in the data differently or perhaps you're looking at a different pair of values than this.

추가 답변 (0개)

카테고리

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

태그

질문:

2020년 7월 29일

댓글:

2020년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by