필터 지우기
필터 지우기

Ask matlab to compare variables per row between two column? Output a number "1" if the values are the same, output number "0" if the values are different.

조회 수: 2 (최근 30일)
dataFolder = uigetdir();%select folder
filePattern = fullfile(dataFolder, '*.csv');
list = dir(filePattern);
Output = table();
for kk = 1:numel(list)
filename = list(kk).name;
data = readtable(fullfile(list(kk).folder, filename));
if numel(list)(:,1)==numel(list)(:,4)
disp('Correct')
value = 1;
elseif numel(list)(:,1)~=numel(list)(:,4)
disp('Incorrect')
value = 0;
end
end
For multiple .csv files in a folder that appear like this:
I want to ask matlab to compare variables per row between column 1 and 4.
Output a number "1" if the values are the same:
numel(list)(:,1)==numel(list)(:,4)
and "0" if they are not:
numel(list)(:,1)~=numel(list)(:,9)
For example row 2 column 1 = 6, column 4 = NaN.
It means I would like to output a column in wich in the row 2 I will have a 0.
Where am I wrong? Something with the syntax for sure but where?
  댓글 수: 2
awezmm
awezmm 2020년 1월 3일
If you compare two NaN's, do you want it to be equal and return 1 or non-equal and return 0?
Myke Ziz
Myke Ziz 2020년 1월 3일
I would like to be equal to 1 yes.
Only when not the same equal to 0, this for numbers and words.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 3일
(Output{:,1} == Output{:,4}) | (isnan(Output{:,1}) & isnan(Output{:,4}))
The second part is needed to implement the "nans are equal" criteria.
  댓글 수: 17
Walter Roberson
Walter Roberson 2020년 1월 5일
value = zeros(1,numfiles);
Though it might be necessary to take special care because of the vector being passed in. I will need to reread the appropriate documentation.
Walter Roberson
Walter Roberson 2020년 1월 10일
https://www.mathworks.com/matlabcentral/answers/498717-extract-the-displayed-column-vectors-into-table-and-csv-file#comment_782904

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by