フィルターのクリア

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 日間)
Dung Le
Dung Le 2016 年 1 月 18 日
コメント済み: Walter Roberson 2016 年 1 月 19 日
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 Center および File ExchangeAuthor Block Masks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by