Use polyfit with cell arrays

조회 수: 14 (최근 30일)
EldaEbrithil
EldaEbrithil 2020년 10월 15일
댓글: Ameer Hamza 2020년 10월 15일
Hi all
i am not able to use polyfit with cell arrays; suppose we have 2 cell arrays A and B with the same number of elements and with cells of non-uniform size. It is possible to obtain the graphical trend of the data in this way:
for i=1:length(A)
figure(1);set(gcf,'Visible', 'on')
plot(A{i},B{i})
xlabel('A')
ylabel('B')
hold on
end
With the same logic I would like to apply polyfit to each curve using the code:
for i=1:length(A)
C{i}= polyfit(A{i},B{i},11);
end
but i receive the error "Unable to perform assignment because brace indexing is not supported for variables of this type."
How can i do that?
Thank you for the help
Regards

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 15일
편집: Ameer Hamza 2020년 10월 15일
I guess you already have a variable in the base workspace named 'C'. In any case, try the following code
C = cell(size(A)); % initialize C
for i=1:length(A)
C{i}= polyfit(A{i},B{i},11);
end
  댓글 수: 2
EldaEbrithil
EldaEbrithil 2020년 10월 15일
Thank you very much Ameer as usual!!
Ameer Hamza
Ameer Hamza 2020년 10월 15일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by