Any suggestions to this algorithm?

2 ビュー (過去 30 日間)
Azar Nejad
Azar Nejad 2018 年 8 月 24 日
コメント済み: Image Analyst 2018 年 8 月 25 日
Hi all,
I have a big problem with my algorithm. I really don’t know what can I do and so confused? If someone have any suggestion that would extremely helpful.
for counter=1:(end of the struct)
*check condition 1
If *condition 1 is true then
counter plus to check the condition 2
Between conditions 1 & 2 there is not fixed amount of data maybe non, 2 or more.
So I need that counter in this loop too.
  4 件のコメント
dpb
dpb 2018 年 8 月 24 日
I agree w/ both posters; while I can kinda' get the drift of what you're trying to say, not enough given to really do anything with.
I think showing a (smallish) example of input and then the desired result and how you determined that result will be the only way anybody will be able to help here...
Image Analyst
Image Analyst 2018 年 8 月 25 日
Azar's "Answer" moved here since it tries (unsuccessfully) to clarify the original post rather than be an "Answer" to the original post.
Thanks all for your support.
This is part of my data:
I deleted some rows to show 'UserEvent'
I want 'X' & 'Y' data between 'onset' and 'offset' where I have 'L' in the 'EventType'
For example in '#Message: onset_P1_8'
I want a variable struct named 'P1_8' or p(1,8) (I really don't know what kind of variable I need!) and the value for this var is []
Sincerely

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2018 年 8 月 25 日
No, you don't (or shouldn't) want this, even though you, and too many other beginners, think so. It can't be stressed too strongly. See the FAQ: https://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F Just don't do it.
You do NOT want to have a struct variable where the name of that variable is determined by part of a string in the "End" field of your structure. If you don't know what possible strings would be there at run-time when you read in your data then how can you refer to that variable with the unknown name when you're writing the code? You can't. So don't do it.
  2 件のコメント
Azar Nejad
Azar Nejad 2018 年 8 月 25 日
really thanks for your care this is my code:
Size = size(Subject); for i=1:Size(1) Event = [Subject(i).End]; parts = regexp(Event,... '(?<Set>[A-Za-z]+)_(?<Paradigm>[A-Za-z]+)(?<Round>\d+)_(?<Trial>\d+)', 'names');
if (strcmp([Subject(i).EventType],'UserEvent'))&& (strcmp([parts.Set],'onset'))
Event1 = [Subject(i).End];
parts1 = regexp(Event1,...
'(?<Set>[A-Za-z]+)_(?<Paradigm>[A-Za-z]+)(?<Round>\d+)_(?<Trial>\d+)', 'names');
while ~(strcmp([parts1.Set],'offset'))
if (strcmp([Subject(i).EventType],'L'))
[Case.name(i)] = struct('Round',[parts1.Round], 'Paradigm',[parts1.Paradigm],...
'Trial',[parts1.Trial]);
[Case.L(i)] = struct('XL_data',[Subject(i).X],...
'Y_data',[Subject(i).Y]);
if (strcmp([Subject(i).EventType],'R'))
[Case.R(i)] = struct('XR_data',[Subject(i).X],...
'YR_data',[Subject(i).Y]);
end
end
i=i+1;
end
end
end
but it doesn't work and my problem in the loop
Image Analyst
Image Analyst 2018 年 8 月 25 日
"Doesn't work" is not very descriptive. At least attach your "Subject" variable in a .mat file with the paper clip icon in case people want to run your code. And see this link so people can read your code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by