Operator ~= matrix dimensions doesn't match

1 visualización (últimos 30 días)
Tammy Chen
Tammy Chen el 30 de Ag. de 2016
Respondida: James Tursa el 30 de Ag. de 2016
Hi all, so I'll just cut to the chase
fidO = fopen('pvtsort.xls','w+');
d = dir('*txt');
for i = 1:length(d)
fid = fopen(d(i).name, 'r'); % open all input txt files, no array
values = textscan(fid,'%*s%*s%s','HeaderLines',4, 'Delimiter','\t');% read only the 3rd column
for n = 1
m = num2str(n * i)
fprintf(fidO,'%s%s\t','Trail',m);
end
for j = 1:length(values{1,1})
pvt = values{1,1}
fprintf(fidO,'%s\t',pvt{j}); %note "the curlies" to dereference cellstr to char
end
fprintf(fidO,'\n')
for f = pvt{j}(pvt{j}~=['False start'])
s = str2double('f')
a = mean(s)
b = median(s)
g = prctile(s,5)
h = prctile(s,95)
k = prctile(s,10)
o = prctile(s,90)
fprintf(fidO,'%s\t%d\t%d\t%d\t%d\t%d\t%d\n','mean; median; lower%5; higher%5; lower%10; higher%10',a,b,g,h,k,o)
end
fid = fclose(fid);
end
fidO = fclose(fidO)
In the code above, I'm trying to have Matlab calculate the stats (mean, median, and a bunch of percentiles) for a string of data I pulled from several text files. Problem is, the values in the strings are not all numbers, some are 'False start'. How can I have Matlab ignore the 'False start' and calculate my stats without them? As you can see, I tried the ~= operator, but ran into issue with the error "Error using ~=. Matrix dimensions must agree.". I also tried NaN the "False start" but that seems even more problematic than using '~='. Any ideas how I can format my data so the matrices match for the ~= operator?
Attached is a screenshot of my workspace from when I ran into this error.
Thanks for looking into this.

Respuestas (1)

James Tursa
James Tursa el 30 de Ag. de 2016
To pick off the cell elements that are not equal to 'False start':
pvt(~strcmp(pvt,'False start'))

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by