Changing from char variable to another input

Forgive my naivity on this one. How can I change a 1x47004 char to a matrix which has letters/words in some cells and numbers in the rest? At present I have the following 6x6 cell.
1x47004 char [] [] [] [] []
1x45843 char [] [] [] [] []
1x46992 char [] [] [] [] []
1x46432 char [] [] [] [] []
1x46459 char [] [] [] [] []
1x48191 char [] [] [] [] []

5 件のコメント

dpb
dpb 2019 年 10 月 8 日
Attach a .mat file with the cell content or show a short section of what you have and what you're trying to get...
Jake Bowd
Jake Bowd 2019 年 10 月 8 日
Thanks for the reply.
I am using the following to load in .mot files, for which I then want to work out certain metrics such as maximum/minimum and range of motion. But when I use the following code the inputs are not in rows/column format.
%% Load in Session Trials
testfiledir = 'D:\Leuven_Visit\Workflow\Modelling\simL\Pre_32L\MFD_opt\Tibia\';
matfiles = dir(fullfile(testfiledir, '*.mot')); %% Loads all .mot files for the above directory
nfiles = length(matfiles);
data = cell(nfiles);
for i = 1 : nfiles
fid = fopen( fullfile(testfiledir, matfiles(i).name) );
data{i} = fscanf(fid,'%c');
fclose(fid);
end
Jake Bowd
Jake Bowd 2019 年 10 月 8 日
Apologies, I didn't attach the .mat file; please see attached.
dpb
dpb 2019 年 10 月 8 日
OK, you're trying to read some custom format it appears.
Attach a section of one of the underlying .mot files so we can see what you're actually starting from.
The conversion from the .mat file is trying to fixup after a mess; better by far to avoid the mess in the first place instead.
Image Analyst
Image Analyst 2019 年 10 月 8 日
What is a .mot file? Is it the same as a .mat file? Did you create it with the save() function?

サインインしてコメントする。

 採用された回答

Joe Vinciguerra
Joe Vinciguerra 2019 年 10 月 8 日
編集済み: Joe Vinciguerra 2019 年 10 月 8 日

2 投票

Your *.mot files are coming in as one very long character array.
You can either try to parse it character-by-character into a cell array, or table, or structure, etc... OR import your data differently.
Try using the readtable function
Try this:
for i = 1 : nfiles
data{i} = readtable(fullfile(testfiledir, matfiles(i).name));
end

10 件のコメント

Jake Bowd
Jake Bowd 2019 年 10 月 8 日
Hi Joe,
Thanks for the support. When I try the readtable an error arises stating its undectable?
Guillaume
Guillaume 2019 年 10 月 8 日
Please attach one of the files you're trying to parse. readtable can always be given hints on how to parse the file.
Jake Bowd
Jake Bowd 2019 年 10 月 8 日
When I try and send a file to you, I get the following message:
Cannot attach this file because:
  • File format is unsupported for files:Pre_32L_NLwalk7_norm_mfd.mot,Pre_32L_NLwalk7_norm_mfd_tf.prs,Pre_32L_NLwalk7_norm_mfd_tf.prx,Pre_32L_NLwalk7_norm_mfd_thickness_tf.prx. Use any of these formats:.bmp, .csv, .fig, .gif, .jpg, .jpeg, .m, .mat, .mdl, .mlx, .slx, .sbproj, .pdf, .png, .txt, .xls, .xlsx, .zip
Is there another way I can send it to you?
Thank you so much for your help and assistance on this. It is very much appreciated.
Kind regards,
Joe Vinciguerra
Joe Vinciguerra 2019 年 10 月 8 日
either rename the extension from .mot to .txt or one of the other options. Or put it in a .zip file.
Jake Bowd
Jake Bowd 2019 年 10 月 8 日
Please see attached for the different types I wish to load in.
Joe Vinciguerra
Joe Vinciguerra 2019 年 10 月 8 日
編集済み: Joe Vinciguerra 2019 年 10 月 8 日
I was able to read them all in okay after changing the extensions from .mot (et.al.) to .csv
the .mot file came in just fine after that. However, the other files need extra massaging on the deliminator settings for the readtable function. You could also play around with csvread and the other similar functions to see which works better for you.
Guillaume
Guillaume 2019 年 10 月 8 日
You don't need to change the extension for readtable to parse the files properly. You just need to specify the 'FileType' as 'text' in the readtable call. 'text' is automatically assumed for extensions .txt, .dat, and .csv.
Guillaume
Guillaume 2019 年 10 月 8 日
The .mot file can indeed easily be read by 'readtable':
mot = readtable('Pre_32L_NLwalk7_norm_mfd.prf', 'FileType', 'text')
The other files, since the number of values per line varies, cannot be read with readtable. A dedicated parser will have to be written.
Jake Bowd
Jake Bowd 2019 年 10 月 8 日
Brilliant, thank you so much for the help getting the .mot files in!
Are you able to direct me to how to create/write dedicated parsers for the other files?
(can you tell that I am new to Matlab?! :) )
Thank you so much
Jake Bowd
Jake Bowd 2019 年 10 月 9 日
Guillaume, how to I notify that I am happy with your answer and mark it as 'answered'?
P.s. if you are able to direct me to how to create/write dedicated parsers for the other files that would be really useful.
Cheers

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by