필터 지우기
필터 지우기

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 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