Storing values using csapi (spline functin)

I have been trying to use csapi. This command will work: x = [0 1 2 3]; y = [0 1 2 3]; csapi(x,y); However, I am trying to let x be a cell array. x = {[0 1 2 3] [0 1 2 3]}; y = [0 1 2 3]; Basically I want my "x" to be a table with different values. csapi(x,y); will not work for this case. Is this possible? I appreciate any help.

Answers (2)

Why not just use a for-loop?
Or you coudl write a wrapper function around csapi that uses a for-loop internally but allows you to call it with a cell array.
Just my $0.02

11 Comments

Well the for loop will not really fix it. I cannot even get one entry store. For instance,
x = [0] [1x2 double] and y = [0 1]; csapi(x,y)
gives me an error: [b,v,l,k] = ppbrk(csapi1(x{i}, reshape(v,prod(sizev(1:m)),sizev(m+1)) ));
post the full code of what you tried, it should be something like this:
C = your cell a cell arrasy
for ii = 1:length(C)
result{ii} = csapi(C{ii},y)
end
My code looks like this:
index = 1
for i = 1:length(a)
for j = 1:length(b)
for k = 1:length(c)
for l = 1:length(d)
y(i,j,k,l) = value_array(index);
index = index+1;
end
end
end
end
st{1} = csapi({a,b,c,d},y);
where a = [1:5], b = [1:3], c = [4:6], d=[50:100]; and value_array = [1 2 3 4 .... length(a)*length(b)*length(c)*length(d)]
Hope this clears my problem. Thanks
Still not going to work because csapi doesn;t want cell arrays!
I would recommend writing
out = csapiCell(Cx,y)
for ii = length(Cx):-1:1
out{ii} = csapi(Cx{ii},y);
end
save those four lines of code as csapiCell somewhere on the MATLAB path.
So csapi doesnt take cell arrays. I understand.
What does this line do?
out = csapiCell(Cx,y)
And to clarify, in csapi(x,y); x has to be one dimensional array.
I would have to come up with something likeL
x = f(a,b,c,d) %refering to my previous code
y = [y1 y2 ... length(x)] %length(x) = length(a)*len(b)*len(c)*len(d)
out = csapi(x,y)
csapiCell the four lines of code I wrote above, if saved as an *.m file will be a wrapper that calls csapi with the contents of each cell. and returns a cell.
Ok Sean, thanks a lot, but tell me, definitively the csapi will not accept a cell array with values, it has to be a single array?
If called correctly it will take a cell array:
doc csapi
according to the document as long as "if x is sequences x1, ..., xm, of lengths n1, ..., nm respectively, then y is expected to be an array, of size [n1,...,nm]"
then why st{1} = csapi({a,b,c,d},y); will not work if
x is a cell array and
y is pretty much (y1..length(a), y2..length(b), y3..length(c), y4..length(d))

Sign in to comment.

I believe based on the comments the best way to do this: Come up with something like this. x = f(a,b,c,d) %refering to my previous code Where x is a unique function of a,b,c,d. y = [y1 y2 ... length(x)] %length(x) = length(a)*len(b)*len(c)*len(d) out = csapi(x,y)

Asked:

on 24 Feb 2012

Edited:

dpb
on 24 Oct 2013

Community Treasure Hunt

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

Start Hunting!