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 次查看(过去 30 天)
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 ^^

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-18
编辑:Walter Roberson 2016-1-18
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 个评论
Dung Le
Dung Le 2016-1-19
编辑:Dung Le 2016-1-19
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 2016-1-19
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))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Author Block Masks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by