Info

This question is closed. Reopen it to edit or answer.

table name res5500 ,row size 762,three column, third column each row have different length,compare the value of each row is same or different. count number of same row and different row, please help me

1 view (last 30 days)
if true
% code
endsamecount=0;
differentcount=0;
a= table2cell(res5500);
% for j=1:762
row1=res5500(1:762,3);
clear allnames;
C = table2cell(row1);
str = string(C);
allnames=regexp(str,' ','split');
var1=allnames(2);
for i=1:length(allnames)
if strncmp(var1,allnames(i,:),2)
samecount=samecount+1;
else
differentcount=differentcount+1;
end
end
  3 Comments
Guillaume
Guillaume on 11 Sep 2018
what wrong with this code?
Lots. For a start, it's not commented so we have no idea what it's trying to do. Then, we have some variables that are created but never used (eg, a). There's also some useless statements (the clear allnames) and of course, converting a table to a cell array is probably a complete waste of time. tables are usually easier to work with than cell arrays.
We also don't know how the table is created from your csv file (just a plain readtable, or something more advanced?)
And again, we don't know what the code is meant to do.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 11 Sep 2018
Edited: Andrei Bobrov on 11 Sep 2018
f = fopen('path_to_file\res_5500.csv');
c = textscan(f,'%s','delimiter','\n');
fclose(f);
n = cellfun(@numel,regexp(c{:}(2:end),'\<\d'));
a = unique(n);
out = [a, histcounts(n,[a;a(end)+1])'];
  2 Comments
jaya paul
jaya paul on 14 Sep 2018
it does not solve my answer, i want to get detail of no of different element and same element in each row count in third column of that table

Community Treasure Hunt

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

Start Hunting!