第2輪:挑選電子郵件中的領導 好吧,所以我的下一個問題是要弄清楚領導是誰在項目中。爲了確定這一點,我們收到一封電子郵件,並且必須找到誰說「你想要......」(大小寫可能會有所不同)。我覺得我的代碼應該適用於大多數情況,但我真的有一個問題想出如何正確填充我的單元陣列。我可以通過它來創建單元陣列,但它只是將電子郵件重新放入。所以每個單元基本上都是這個名字。在電子郵件中查找名稱(低級別I/O)
function[Leader_Name] = teamPowerHolder(email)
email = fopen(email, 'r'); %// Opens my file
lines = fgets(email); %// Reads the first line
conversations = {lines}; %// Creates my cell array
while ischar(lines) %// Populates my cell array, just not correct
Convo = fgets(email);
if Convo == -1 %// Prevents it from just logging -1 into my cell array like a jerk
break; %// Returns to function
end
conversations = [conversations {lines}]; %// Populates my list
end
Sentences = strfind(conversations,'Do you want'); %// Locates the leader position
Leader_Name = Sentences{1}; %// Indexes that position
fclose(email);
end
我非常需要做的是找到「/ n」字符(所以爲什麼我使用與fgets),但我不知道如何使它做到這一點。我試圖讓我的while循環如下所示:
while lines == '/n'
但這不正確。我覺得我知道該怎麼做'/ n',我想不起來。所以我會很感激一些提示或技巧。我總是可以嘗試對這個函數進行strsplit或strtok,但是我需要填充我的單元陣列,這樣可能會變得混亂。
請和感謝幫助:)
Test Case:
Anna: Hey guys, so I know that he just assigned this project, but I want to go ahead and get started on it.
Can you guys please respond and let me know a weekly meeting time that will work for you?
Wiley: Ummmmm no because ain't nobody got time for that.
John: Wiley? What kind of a name is that? .-.
Wiley: It's better than john. >.>
Anna: Hey boys, let's grow up and talk about a meeting time.
Do you want to have a weekly meeting, or not?
Wiley: I'll just skip all of them and not end up doing anything for the project anyway.
So I really don't care so much.
John: Yes, Anna, I'd like to have a weekly meeting.
Thank you for actually being a good teammate and doing this. :)
out2 = teamPowerHolder('teamPowerHolder_convo2.txt')
=> 'Anna'
你忘了包括MATLAB標籤。對你的帖子做了一個小小的修改。 – rayryeng 2014-10-11 15:49:46
糟糕。這可能是最重要的部分。 – 2014-10-11 17:37:36