Filter löschen
Filter löschen

Error in Untitled3 (line 11): mask = z{:,1} == c{i,1} & z{:,2}==c{j,2} & z{:,3} == c{k,3} & z{:,4} == c{h,4}; Please help me !!

3 Ansichten (letzte 30 Tage)
Dung Le
Dung Le am 18 Jan. 2016
Kommentiert: Walter Roberson am 19 Jan. 2016
I have two file xlsx in which criteria.xlsx has 4 columns, the two first of these columns are texts, the remaining two columns are numbers.
In the same way, in file mean_std. xlsx, i have 5 columns, the two first of these columns are texts, the remaining three columns are numbers.
When I run the code below, i have message from matlab:
Error using ==
Too many input arguments.
Error in Untitled3 (line 11)
mask = z{:,1} == c{i,1} & z{:,2}==c{j,2} & z{:,3} == c{k,3} & z{:,4} == c{h,4};
Here is the code:
clear all
clc
[a,b,c] = xlsread('criteria.xlsx');
[x,y,z] = xlsread('mean_std.xlsx');
for i=1:49
for j=1:21
for k=1:2
for h=1:3
mask = z{:,1} == c{i,1} & z{:,2}==c{j,2} & z{:,3} == c{k,3} & z{:,4} == c{h,4};
if size(z{mask,1},1) > 3
m = mean(z{mask,5});
z{mask,6} = m;
n = std(z{mask,5});
z{mask,7} = n;
end
end
end
end
end
xlswrite('mean_std.xlsx',z)
Thank you so much ^^

Antworten (1)

Walter Roberson
Walter Roberson am 18 Jan. 2016
Bearbeitet: Walter Roberson am 18 Jan. 2016
mask = strcmp(z(:,1), c{i,1}) & strcmp(z(:,2), c{j,2}) & strcmp(z(:,3), c{k,3}) & strcmp(z(:,4), c{h,4});
  2 Kommentare
Dung Le
Dung Le am 19 Jan. 2016
Bearbeitet: Dung Le am 19 Jan. 2016
Could you please explain why you use () for z but {} for c while they are all raw data. In my code, I use {} for both z and c, but my code does not run.
Thanks :)!
Walter Roberson
Walter Roberson am 19 Jan. 2016
c{i,1} is one value and will come out as a string.
z(:,1) is a cell array of strings, multiple strings.
You can compare a cell array of strings to a single specific string; see http://www.mathworks.com/help/matlab/ref/strcmp.html#btwfyr6-2
You want strcmp() to be called with exactly two arguments. c{i,1} is exactly one argument. z{:,1} expands to as many arguments as there are rows in z. z(:,1) expands to exactly one argument.
If you prefer you could use
strcmp(z(:,1), c(i,1))

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Author Block Masks finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by