how to manipulate a cell

1 回表示 (過去 30 日間)
Navid
Navid 2013 年 11 月 24 日
回答済み: Navid 2013 年 11 月 25 日
Hi I have 1621x1 cell and each row is something like this: ;1800742;0,0000;0,0000;0,0000;;;;;;;1,4400;0,0000;0,0000;0,0000;0,0000;
";" is delimiter between different values.
I need to find the blank places in each row and fill it with a word like "None". As a beginner I need to know how can I access the blank places?is it possible to at first store the values in an array and then find the blank places?if yes how can I do that?
I would really appreciate any helps.
Thanks,Navid

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 24 日
A={1800742;0;0;0;[];[];1.4400;0;0;[];0}
A(cellfun('isempty',A))={'none'}
  22 件のコメント
Navid
Navid 2013 年 11 月 24 日
the numbers are floating point and the comma represent that,for example:(10,5 represent 10.5)
and the different numbers are separated by semicolon it could be string or double,i just need to fill the blank places(the places which there is nothing between two semicolons ) with "none".
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 24 日
編集済み: Azzi Abdelmalek 2013 年 11 月 24 日
Try this
clear
fid = fopen('sample.txt');
res={};
while ~feof(fid)
res{end+1,1} =fgetl(fid);
end
fclose(fid);
A=strrep(res,',','.');
B=regexp(A,';','split');
for k=1:numel(B)
C(k,:)=B{k};
end
C=cellfun(@str2double,C,'un',0);
idx=isnan(cell2mat(C));
C(idx)={'none'}

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

その他の回答 (1 件)

Navid
Navid 2013 年 11 月 25 日
Dear Azzi Abdelmalek
Many thanks for your times and helps,it works great.this is exactly what I wanted. thank you so much.
Best,Navid

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by