Subscripted assignment dimension mismatch in for loop

Does anyone know what's wrong with this? I have tdatas and tissdatas with size (225x4). Every time I run this, I get the following error: Subscripted assignment dimension mismatch. Where am I wrong in this code? I just don't understand it or find it.
for i=1:length(tdatas(1,:))
fun = @(p,tdatas) objfunction(p,tdatas,tu);
z(i)=lsqcurvefit(fun,param0,tdatas(:,i),...
tissdatas(:,i),[0 0 0 0],[1 1 1 1],options);
end

댓글 수: 1

Or the following: In an assignment A(:) = B, the number of elements in A and B must be the same.

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

 채택된 답변

Star Strider
Star Strider 2017년 6월 11일
You are estimating and returning 4 parameters, and assigning them to a 1 dimensional scalar. I do not know whether you are returning row or column vectors, so the easiest way is to use ‘z’ as a cell array:
z{i} = lsqcurvefit(fun,param0,tdatas(:,i),...
tissdatas(:,i),[0 0 0 0],[1 1 1 1],options);
Note the curly brackets ‘{}’ denoting cell array indexing.

댓글 수: 4

Arbol
Arbol 2017년 6월 11일
편집: Arbol 2017년 6월 11일
This work, I don't know why. But it should return a scalar value? since I index tdatas(:,1)? Or is it because of my anonymous function? So it looks like it doesn't return a scalar value then. Hmm weird.
It should not return a scalar value in your code. (It would if you were only fitting one parameter.) The lsqcurvefit function estimates (and returns) the best-fit parameter vector for your model and data (and other outputs if you ask for them).
The lsqcurvefit function returns a vector because your anonymous function fits 4 parameters. There is nothing wrong with your code or with lsqcurvefit.
Please see the documentation on lsqcurvefit for an explanation of what it returns.
Arbol
Arbol 2017년 6월 11일
편집: Arbol 2017년 6월 11일
Oh sorry, yes, you are right! It will return 4 parameters. You are the best man! haha
Thank you!

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

추가 답변 (0개)

카테고리

태그

질문:

2017년 6월 11일

댓글:

2017년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by