A matrix with class of sym, but symvar() command gives empty results
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muzaffer Citir
am 30 Dez. 2019
Kommentiert: Muzaffer Citir
am 2 Jan. 2020
I have a huge matrix with more than 180 different symbolic variable. I need to change variables into vector form such from q1, q2 ... to q(1), q(2)...
I wrote a code as below, I succided to change variable. But problem, now I lost my symbolic variables, when I query my variables with symvar(), I get empty results.
This is problem when I try to change from symbolic to function with matlabFunction() command. Naturally, it can not find any variable in my symbolic func.
Please help me
That is the result wtih symvar():
>> symvar(tests.test5.symbolicObsW{3,1})
ans =
Empty sym: 1-by-0
That is result with matlabFunction():
>> testRecords.funcObsw3 = matlabFunction(tests.test5.symbolicObsW{3,1});
Warning: Function 'sq' not verified to be a valid MATLAB function.
for cJ=1:6
tic;
for t=NumRow
ObsWsym{cJ,:}(t,:) = subs(regressors{cJ,1}(1,:), [q1, q2, q3, q4, q5, q6,...
dq1, dq2, dq3, dq4, dq5, dq6,...
ddq1, ddq2, ddq3, ddq4, ddq5, ddq6],...
[sq(18*t-18+1), sq(18*t-18+2), sq(18*t-18+3),sq(18*t-18+4),sq(18*t-18+5),sq(18*t-18+6),...
sq(18*t-18+7), sq(18*t-18+8), sq(18*t-18+9),sq(18*t-18+10),sq(18*t-18+11),sq(18*t-18+12),...
sq(18*t-18+13), sq(18*t-18+14), sq(18*t-18+15),sq(18*t-18+16),sq(18*t-18+17),sq(18*t-18+18)]); %#ok<AGROW>
end
disp(['Observation matrix (',...
num2str(size(ObsWsym{cJ,1},1)),...
'X',num2str(size(ObsWsym{cJ,1},2))...
') for Joint ',num2str(cJ),' is generated by using Regressor']);
toc;
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 30 Dez. 2019
You should probably just use matlabFunction with the 'vars' option. Pass in a cell array. Within the cell array, each variable that is listed in the same entry will be bundled into a single parameter. So for example if you had
q = symvar('q', [1 150]);
p = symvar('p', [1 30]);
testRecords.funcObsw3 = matlabFunction(tests.test5.symbolicObsW{3,1}, 'vars', {q, p})
then the function would be created with two parameters, one of which was expected to be a row vector of length 150, and the other was expected to be a row vector of length 30.
Warning: Function 'sq' not verified to be a valid MATLAB function.
You appear to be trying to mix array indexing with symbolic work. That will fail most of the time: never try to index with a symbolic variable (unless you really really know what you are doing.)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!