I have a cell array that contains some numbers and empty spaces, say
A=[ , ,4,5,6,7,,,8,,5, , ,]
I want to interpolate A using interp1('previous') so that it becomes
A=[ , ,4,5,6,7,7,7,8,8,5, , ,]
That it is a cell array is making it difficult to use interp1. What I have got so far is this:
A={betdaqv{5,:}};
x = 1:length(A);
xi = 1:length(A);
emptyloc=find(cellfun(@isempty,A));
zs = emptyloc;
A(zs)=[];
x(zs)=[];
But then applying the following doesn't work:
output1 = interp1(x, A, xi,'previous')
See attached for betdaqv.

댓글 수: 3

Stephen23
Stephen23 2018년 12월 7일
편집: Stephen23 2018년 12월 7일
This is not a cell array and it is not valid MATLAB syntax:
A=[ , ,4,5,6,7,,,8,,5, , ,]
Please at least give us something that we can work with.
You forgot to attach betdaqv. Make it easy for us to help you, not hard.
Save betdaqv in a .mat file and then upload
save('answers.mat', 'betdaqv');
Once we have it, we can try things and help you.
Sam Smith
Sam Smith 2018년 12월 7일
Thank you. I mean A should have curly brackets, not square.

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

 채택된 답변

Stephen23
Stephen23 2018년 12월 7일
편집: Stephen23 2018년 12월 7일

1 개 추천

>> A = {[],[],4,5,6,7,[],[],8,[],5,[],[]};
>> idx = find(~cellfun('isempty',A));
>> idy = idx(1):idx(end);
>> new = interp1(idx,[A{idx}],idy,'previous');
>> A(idy) = num2cell(new);
>> A{:}
ans = []
ans = []
ans = 4
ans = 5
ans = 6
ans = 7
ans = 7
ans = 7
ans = 8
ans = 8
ans = 5
ans = []
ans = []

댓글 수: 1

Sam Smith
Sam Smith 2018년 12월 7일
Thank you. I'm happy you focussed on the substance of my question.

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

추가 답변 (2개)

madhan ravi
madhan ravi 2018년 12월 7일
편집: madhan ravi 2018년 12월 7일

1 개 추천

you may look into fillmissing released in 2016b
Image Analyst
Image Analyst 2018년 12월 7일

0 개 추천

In the following code, your A does not have any empty values:
s = load('answers.mat')
betdaqv = s.betdaqv
A={betdaqv{5,:}};
x = 1:length(A);
xi = 1:length(A);
emptyloc=find(cellfun(@isempty,A));
zs = emptyloc;
A(zs)=[];
x(zs)=[];
Why do you think it should?

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2018년 12월 7일

댓글:

2018년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by