MATLAB Answers

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side

조회 수: 2(최근 30일)
Christine
Christine 2021년 9월 12일
댓글: Christine 2021년 9월 13일
%% function
syms x real
f = x^3*551-x^2*4180+1.2030*10^4*x+4375;
A = readmatrix(char(File)); % matrix A double of 160x100
B = zeros(160,100); % matrix B of 160x100
%% Solve function f to x with given y values from the matrix A and save in B
parfor i=1:16000
B(i)= double(solve(f==A(i),x));
end
Using the for loop the error does not occur. Can someone help me? How can I solve this?

채택된 답변

Matt J
Matt J 2021년 9월 12일
편집: Matt J 2021년 9월 12일
parfor i=1:16000
tmp=double(solve(f==A(i),x));
if isempty(tmp),
warning 'No solutions found.'
tmp=nan;
elseif ~isscalar(tmp)
warning 'Multiple solutions found.'
tmp=tmp(1);
end
B(i)=tmp;
end

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by