is it possible to convert iddata to cellstr

Dear matlab users,
Is it possible to convert iddata to cellstr? i tried following code but it dont works.
cellstr(num2str(data.y(:,1)))]; %
%data.y(:,1) has this form 1×1 cell array {500×1 double}
500×1 char array
'0.0833333'
' 0.166667'
' 0.25'
' 0.333333'
' 0.416667'
' 0.5'
' 0.583333'
' 0.666667'
' 0.75'
.........
in this format i want vector
Thank you very much

 Respuesta aceptada

Star Strider
Star Strider el 29 de Oct. de 2019
Another approach:
data = iddata(rand(1,10)', (0:9)', 0.1); % Create ‘iddata’ Object
y = data.OutputData; % Get ‘OutputData’ As Double Array
ycs = cellstr(num2str(y)); % Convert To Cell Array Of Strings

8 comentarios

Ill ch
Ill ch el 29 de Oct. de 2019
Editada: Ill ch el 29 de Oct. de 2019
Hello Star, Thank you for your reply. yes the same thing what you done in
data = iddata(rand(1,10)', (0:9)', 0.1); % Create ‘iddata’ Object
y = data.OutputData; % Get ‘OutputData’ As Double Array
ycs = cellstr(num2str(y)); % Convert To Cell Array Of Strings
But In my case i have bunch of the data in cell array. I could not access directly
y = data.OutputData; % Get ‘OutputData’ As Double Array
ycs = cellstr(num2str(y));
As i have 1*38 cell array. Your code work for one single data vector but here i have problem to access the data. you can check attached file. Thank you in advanvce
y: 1×38 cell array % there are 38 column vectors
Columns 1 through 5
{500×1×0 iddata}
Daniel M
Daniel M el 29 de Oct. de 2019
Your cells are empty.
Ill ch
Ill ch el 29 de Oct. de 2019
Editada: Ill ch el 29 de Oct. de 2019
Hello Daniel,
Thank you for your reply. No they are not empty. I can plot all 38 cells with same data which i attached.
try after loading: plot(y{1}) or any number till 38. you will get results
I disagree! (At least the first and last ones are not empty. I did not check the others.)
Try this:
D = load('Ill ch mydata.mat');
y = D.y_Out;
for k = 1:numel(y)
ycs{k} = num2str(y{k}.OutputData); % Create Cell Strings
end
Check = [ycs{1}(1:5,:), ycs{end}(1:5,:)] % Confirm Result (Delete Later)
producing:
Check =
5×22 char array
' 0.095621 0.060427'
' 0.082729 0.073796'
' 0.060678 0.074488'
' 0.033146 0.065841'
' 0.0034351 0.050947'
Noting that ‘ycs’ indicates ‘y cell string’.
I have no idea why you want them as strings. That makes them more difficult to work with.
Ill ch
Ill ch el 29 de Oct. de 2019
Thank you very very very much. It works. In order to save in csv i wanted to have string.
Daniel M
Daniel M el 29 de Oct. de 2019
Oh, I see. Didn't realize you had written your own class. Just saw the size of the cell. Glad it is solved.
Star Strider
Star Strider el 29 de Oct. de 2019
@Ill ch — As always, my pleasure.
You can (and it is best to) leave them as numeric if you want to save them as a .csv file. The problem now is that saving them as strings to your .csv file creates the additional problem of converting them back to numeric data later, when the .csv file is read.
@Daniel M — Ill ch did not create the class. This is the nature of the output that the System Identification Toolbox iddata function produces.
Daniel M
Daniel M el 29 de Oct. de 2019
Editada: Daniel M el 29 de Oct. de 2019
Ah, I see. I don't have this toolbox and had never heard of it before. help iddata redirected me to help griddata

Iniciar sesión para comentar.

Más respuestas (2)

Daniel M
Daniel M el 23 de Oct. de 2019
Editada: Daniel M el 23 de Oct. de 2019
Close, but you need to access the contents of the cell array, not the entire cell array itself.
data.y(:,1) = {rand(500,1)};
output = cellstr(num2str(data.y{:,1}));

4 comentarios

Ill ch
Ill ch el 23 de Oct. de 2019
Thank you very much
Daniel M
Daniel M el 29 de Oct. de 2019
If it's not working for you, can you say why? (Is there a specific error?) Could you also upload your data, I can take a look.
Hi Daniel,
Thank you very much for your reply. Your code is for particularly random values for it your code works. But in my case i have problem to access the contents from cell array. as looks below my data structure:
Name Size Bytes Class Attributes
y 1x38 342362 cell
y =
1×38 cell array
Columns 1 through 5
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 6 through 10
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 11 through 15
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 16 through 20
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 21 through 25
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 26 through 30
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 31 through 35
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
Columns 36 through 38
{500×1×0 iddata} {500×1×0 iddata} {500×1×0 iddata}
when i am using direct cellarray it doesnt work.
cellstr(num2str(y{16}))
Error using num2str (line 53)
Input to num2str must be numeric.
could you please help me how to access the contents of the cell array, instead of the entire cell array itself.
Thank you very much in advance
Daniel M
Daniel M el 29 de Oct. de 2019
500x1x0 means your arrays are empty. You don't have any data.

Iniciar sesión para comentar.

Rajiv Singh
Rajiv Singh el 5 de Nov. de 2019
From iddata object "data", you can fetch the data arrays as cells using:
y = pvget(data,'OutputData');
In your latest query, y is a cell array of iddata objects. Thus x1 = y{1} will return one iddata object. Then pvget(x1,'OutputData') will return the value of its "OutputData" property as a cell array.
Note that size of 500x1x0 for an iddata object means that the data has 500 samples, 1 output and no inputs signals. The size() operator is specialized (overridden) for iddata objects.

Productos

Versión

R2019a

Preguntada:

el 23 de Oct. de 2019

Respondida:

el 5 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by