data type with calling script in Matlab

Typically: "How do I... ", "How can I... " questions
Post Reply
CroCr
Posts: 75
Joined: 29 Dec 2022, 01:47

data type with calling script in Matlab

Post by CroCr »

i'm trying to get data from CoppeliaSim via calling a script in Matlab using ZeroMQ API. It seems CoppeliaSim mixes different types of data. For example, when I can q_dq_data = sim.callScriptFunction("get_q_and_dq",scriptHandle); it returns cell array with double (64-bit) and single (32-bit) types, therefore, I can't use cell2mat function in matlab. Is there a way to force CoppeliaSim to use one type?

fferri
Posts: 1230
Joined: 09 Sep 2013, 19:28

Re: data type with calling script in Matlab

Post by fferri »

You need to ensure that all elements of the cell array are of the same type before using cell2mat. You can convert all elements to either double or single.

You can iterate over the elements of the cell array and convert each element.
e.g.:

Code: Select all

for i = 1:length(q_dq_data)
    q_dq_data{i} = double(q_dq_data{i});
end
q_dq_mat = cell2mat(q_dq_data);

Post Reply