現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
how to manipulate a cell
1 回表示 (過去 30 日間)
古いコメントを表示
Navid
2013 年 11 月 24 日
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
2013 年 11 月 24 日
A={1800742;0;0;0;[];[];1.4400;0;0;[];0}
A(cellfun('isempty',A))={'none'}
22 件のコメント
Navid
2013 年 11 月 24 日
Thanks for your answer,
unfortunately it did not work.
maybe because the blank places in the cell are like ;;; not like [];[];[]
could it be the reason?
Azzi Abdelmalek
2013 年 11 月 24 日
A={1800742 ;';' ;0;0;0; ';' ;1.4400;0;0;';';0}
B=cellfun(@num2str,A,'un',0)
A(strcmp(B,';'))={'none'}
Navid
2013 年 11 月 24 日
could you please explain about lines? I'm getting error,maybe I should change something.
Thanks
Navid
2013 年 11 月 24 日
yes sure, there is a 1621x1 cell,and this is on of the rows:
;1800742;0,0000;0,0000;0,0000;1,4400;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;2,5500;;;;;;0,0000;-8,8000;12,1600;12,1600;15,0000;0,0000;-0,5000;
As you in the second line there is ;;;;;; ,it means there is no value,and I need to fill this places like this:
;1800742;0,0000;0,0000;0,0000;1,4400;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;0,0000;2,5500;none;none;none;none;none;0,0000;-8,8000;12,1600;12,1600;15,0000;0,0000;-0,5000;
Many thanks for your attention.
Azzi Abdelmalek
2013 年 11 月 24 日
編集済み: Azzi Abdelmalek
2013 年 11 月 24 日
If A is your array, when type
A(1:20)
What do you get?
Navid
2013 年 11 月 24 日
as I told you the cell is 1621x1,I mean there is 1621 rows and just one column. all of mentioned values are in the first row and first column.
actually I had an ASCII file and import it.this is my code for importing part:
fed = fopen('Antos_2013-11-07_07-08-58.asc');
mydata = textscan(fed,'%s');
it gives me "mydata" which is a cell with 1621 rows and one column.
Navid
2013 年 11 月 24 日
I should add that when I type mydata(1:20) I'm getting this error:
Index exceeds matrix dimensions.
Error in plotrand (line 3)
mydata(1:20);
Navid
2013 年 11 月 24 日
I've already written you,it gives me:
Name Size Bytes Class Attributes
mydata 1x1 12422212 cell
Azzi Abdelmalek
2013 年 11 月 24 日
編集済み: Azzi Abdelmalek
2013 年 11 月 24 日
TRY THIS
B=cellfun(@num2str,mydata{1},'un',0)
mydata(~cellfun('isempty',regexp(B,';+','start')))={'none'}
Navid
2013 年 11 月 24 日
sry for taking your time but it gives a cell which is not still correct:
mydata 1x16200 1944000 cell
and in all 16200 elements has been written none.
I think I need to change the code to get correct result,could you just explain the lines please,I just need to understand how does it work.
Thanks
Azzi Abdelmalek
2013 年 11 月 24 日
編集済み: Azzi Abdelmalek
2013 年 11 月 24 日
doc cellfun
doc regexp
Post a sample of your file
Navid
2013 年 11 月 24 日
my file is something like this attachment.
and this is the code for importing:
fed = fopen('sample.txt');
mydata = textscan(fed,'%s');
Azzi Abdelmalek
2013 年 11 月 24 日
Can you explain what a comma , represent in your file, and how your data are separated, and the type your data :string or double? You can read your file line by line
fid = fopen('sample.txt');
res={};
while ~feof(fid)
res{end+1,1} =fgetl(fid);
end
fclose(fid);
celldisp(res)
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
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
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 Exchange で Programming Utilities についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
