第 2 轮:在电子邮件中挑选领导者 好的,所以我的下一个问题是试图找出项目中的领导者。为了确定这一点,我们会收到一封电子邮件,并且必须找到说“你想要...”的人(大小写可能会有所不同)。我觉得我的代码大部分应该都可以工作,但是我在弄清楚如何正确填充单元格数组时确实遇到了问题。我可以用它来创建单元阵列,但它只是将电子邮件重新放入其中。所以每个单元格基本上就是名字。
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'