Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
Dung Le
Dung Le le 18 Jan 2016
Commenté : Walter Roberson le 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 ^^

Réponses (1)

Walter Roberson
Walter Roberson le 18 Jan 2016
Modifié(e) : Walter Roberson le 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 commentaires
Dung Le
Dung Le le 19 Jan 2016
Modifié(e) : Dung Le le 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 le 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))

Connectez-vous pour commenter.

Catégories

En savoir plus sur Author Block Masks dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by