How to use if statements to compare data from matlab with excel data?

Hey there guys, I'm new here and I'm doing a research for my thesis about eye detection. I've got the exact eye position in a .csv file as shown in this picture:
problem is, there are some of the frames that is not detected and needed to be skipped from the frameNum as you can see in this excel file, there is no frame 9, 10, 11, 12, 13 and many more.
BB = step(EyeDetectKanan,muka); %in this line, the frameNum should be compared with the Frame column in excel.
boxRightEye = BB;
My proposed algorithm for this problem is: 1. If frameNum = Frame, then show the value of right x, right y, right w, right h (without the commas like in this picture)
2. If frameNum isn't in Frame, then skip into the next frameNum 3. This process will be continued until the end of the file.
My questions are, is it possible to use if statements between matlab and excel? and how can I do these algorithms I made?
Thanks. Sorry for the bad view and english...

3 Comments

You can read in your data in Excel into Matlab; wouldn't that solve your problem? The readtable command is probably useful.
I think that's not the case here as I don't know how to use if statements between them.
Maybe something like in MATLAB?
for i = 1:10
if i ~= 5
continue
end
disp(i)
end

Sign in to comment.

 Accepted Answer

for fn = 1 : frameNum
[tf, idx] = ismember(fn, Frame);
if tf
rx = rightx(idx); ry = righty(idx); rw = rightw(idx); rh = righth(idx);
lx = leftx(idx); ly = lefty(idx); lw = leftw(idx); lh = lefth(idx);
...
end
end

7 Comments

Thank you for your answer. But turns out the import data feature on MATLAB only turns my file into variables. When I tried to use readtable, it shows an error:
T = readtable('C:\Users\Kenny\Desktop\skripsi\hasil oto\Ahen.csv')
Error using readtable (line 129)
Unable to open file 'C:\Users\Kenny\Desktop\skripsi\hasil oto\Ahen.csv'.
This error also occured when I use csvread:
M = csvread('C:\Users\Kenny\Desktop\skripsi\hasil oto\Ahen.csv')
Error using csvread (line 34)
File not found.
I'm prety sure that the file is in that very directory. Thanks in advance.
What is shown for
exists('C:\Users\Kenny', 'dir')
exists('C:\Users\Kenny\Desktop', 'dir')
exists('C:\Users\Kenny\Desktop\skripsi', 'dir')
exists('C:\Users\Kenny\Desktop\skripsi\hasil oto', 'dir')
ls('C:\Users\Kenny\Desktop\skripsi\hasil oto\*.csv')
There appears to be spaces in those file names. 'Ahen .csv'
yes... I just realize that just now. Now I've successfully imported the csv file into MATLAB. Now, how can I use if statement just like your code? It seems like I can't call the Frame column. Here is my code and output:
I tried to store the table with the T.
Thanks in advance.
for fn = 1 : frameNum
[tf, idx] = ismember(fn, T.Frame);
if tf
thisrow = T(idx,:);
rx = thisrow.rightX; ry = thisrow.rightY; rw = thisrow.rightW; rh = thisrow.rightH;
lx = thisrow.leftX; ly = thisrow.leftY; lw = thisrow.leftW; lh = thisrow.leftH;
...
end
end
It works. Big thanks mate. It still has one flaw though: some of the missing Frame in the .csv file is still shown in the result. It is shown as a direct copy-paste from the Frame before as you can see in this picture
There are no Frame 1319, 1320, 1324, and 1327 on this .csv
Meanwhile, there are in this result of the code. I tried to use continue but it shows only the missing Frame(s).
Big thanks for your help, mate.

Sign in to comment.

More Answers (1)

No, it is not possible to use "if" statements between excel and MATLAB.
You have two choices:
  1. Read the entire file and discard what you do not need;
  2. Read one line at a time and make decisions based upon the content.
To read the entire file at one time, xlsread(), readtable() and textscan() are all good routines.
To read one line at a time, textscan() can still be useful, but so can fgetl() together with strsplit()

1 Comment

I've tried to use import data function in MATLAB and it does the job. now, i'm in a problem with loops.
for x = 1:frameNum
for y = 1:Frame
if x == y
fprintf('Sama dari %d\n', Frame);
else fprintf('Kelaut aja\n');
end
% try
% img = read(openVideo, x);
% catch exception
% continue;
end
end
This code returns the exact Frame that is on the excel file, but it seems that y isn't increasing.
Oh yea, here is the excel data that I've imported to MATLAB
Thanks in advance.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!