how to print in matlab in this format 1 1:2 2:6 3:7 4:8......?

1 回表示 (過去 30 日間)
Sheema Khattak
Sheema Khattak 2014 年 8 月 14 日
コメント済み: Image Analyst 2014 年 8 月 22 日
1 1:2 2:6 3:7 4:8
1 1:9 2:5 3:2 4:1
2 1:3 2:1 3:3 4:9
.
.
.
.
.
the 1,2,3,4,are indices and values after : are random around 133 different values while 1,2,3 are categories how can I write a program for it some of the chunk I designed is given
r=regexp(s, '\w{1,3}', 'match');
l=length(r);
co=':';
for j=1:l
prompt='Enter the label for class';
str = input(prompt,'s');
f=find(r);
fprintf('%s\t%i%c',str,f,co,disp(r));
end
but don't get any output all I get is erroneous results
  1 件のコメント
per isakson
per isakson 2014 年 8 月 14 日
What is the value of s? ... and of r?

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

回答 (1 件)

Image Analyst
Image Analyst 2014 年 8 月 14 日
How about this:
for j = 1 : 3 % do for 3 rows.
% Get a new set of 4 random numbers in the range 1 to 131.
r = randi(133, 1, 4);
prompt = sprintf('Enter the label for class #%d : ', j);
str = input(prompt,'s');
fprintf('%s\t',str);
for k = 1 : length(r)
fprintf('%d:%d ', k, r(k));
end
fprintf('\n');
end
msgbox('Done with demo');
  3 件のコメント
Image Analyst
Image Analyst 2014 年 8 月 18 日
Alright, just replace my "r = " line with the actual numbers you get from using regexp() or however you get them. That's what I was expecting you to do. I just used random numbers because you didn't give us any data to work with.
Image Analyst
Image Analyst 2014 年 8 月 22 日
Have you still not gotten it to work yet?

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by