Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
precise selection in a for loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, I just created a for loop and this is correct, but now I would only select positions from 30 to 48 for each "essai" but I am not sur how to do that whithout matrix size problem...
for essai = 1:length (nb_essai)
% for essai = 1:length (nb_essai)
num_ess = [];
num_ess = find (num(:,24) == essai);
Val_CursX_ess = num(num_ess,6);
Val_CursY_ess = num(num_ess,7);
Val_Quest_ess = txt(num_ess,36);
Val_Indice_ess = txt(num_ess,40);
Val_Valid_ess = txt(num_ess,33);
댓글 수: 0
이 질문은 마감되었습니다.
답변 (1개)
Walter Roberson
2015년 7월 17일
After
num_ess = find (num(:,24) == essai);
add
num_ess = num_ess(num_ess >= 30 & num_ess <= 48);
댓글 수: 10
Alexandre Williot
2015년 7월 17일
편집: Alexandre Williot
2015년 7월 17일
Thank you ! But now I have this error message
??? Index exceeds matrix dimensions.
Error in ==> script_pour_mes_donnees_MO_exp2_TEST2_300ms at 86
if strcmp(Val_Indice_ess_Quest(1,:),'Neutre')==1
Because after the loop above I have another loop:
for ques = 1:2
Question_interet = Type_Questions{ques};
pos_question = find(strcmp(Question_interet,Val_Quest_ess) == 1);
Val_CursX_ess_Quest = Val_CursX_ess(pos_question,1);
Val_CursY_ess_Quest = Val_CursY_ess(pos_question,1);
Val_Quest_ess_Quest = Val_Quest_ess(pos_question,1);
Val_Indice_ess_Quest = Val_Indice_ess(pos_question,1);
Val_Valid_ess_Quest = Val_Valid_ess(pos_question,1);
if ques == 1
pos_ok = [];
pos_ok = find(strcmp('Semantique',Val_Indice_ess_Quest) == 0);
Val_Indice_ess_Quest = Val_Indice_ess_Quest(pos_ok,1);
Val_CursX_ess_Quest = Val_CursX_ess_Quest(pos_ok,1);
Val_CursY_ess_Quest = Val_CursY_ess_Quest(pos_ok,1);
Val_Quest_ess_Quest = Val_Quest_ess_Quest(pos_ok,1);
Val_Valid_ess_Quest = Val_Valid_ess_Quest(pos_ok,1);
% faut dégager les semantiques et conserver le reste
% --> créer un nouveau Val_Indice_ess_Quest
end
%-- Etat Indice -- Emo ou Neutre? --
% Code_Indice --> 1 pour Neutre
% Code_Indice --> 2 pour Emo
if strcmp(Val_Indice_ess_Quest(1,:),'Neutre')==1
code_Indice = 1;
elseif strcmp(Val_Indice_ess_Quest(1,:),'Emo')==1
code_Indice = 2;
else
code_Indice = 999;
end
if strcmp(Val_Valid_ess_Quest(1,:),'valide')==1
code_Vald = 1;
elseif strcmp(Val_Valid_ess_Quest(1,:),'invalide')==1
code_Vald = 2;
else
code_Vald = 999;
end
Walter Roberson
2015년 7월 18일
I do not understand that code.
What is class(Question_interet) ? Is it character array or is it cell array of string?
Why are you using those strange find() on strcmp() instead of using the two-output version of ismember() ?
[found, idx] = ismember('string', Cell_Array_Of_Strings)
Alexandre Williot
2015년 7월 18일
Ok, things are in this manner because at the start I load lot of files and in these files my vector begins with the word 'semantique' or the word 'emotion'. So I needed to create a for loop with if. I don't know if I am clear but I try to be. Ask me again if not. And I didn't know the ismember function.
Type_Questions = {'Semantique' 'Emotion'};
thank you.
Walter Roberson
2015년 7월 18일
Please rewrite your code using ismember()
Also please note that there is no need to test
strcmp() == 1
The result of strcmp() is true or false directly so you can leave out the "== 1" such as
if strcmp(A,B)
or
find(strcmp(A,B))
Alexandre Williot
2015년 7월 19일
Ok, tkank you, I will try but I do not think this is the origin of the problem of my matrix size, isn't it?
Alexandre Williot
2015년 7월 19일
But the problem is on
Error in ==> script_pour_mes_donnees_MO_exp2_TEST2_300ms at 86
if strcmp(Val_Indice_ess_Quest(1,:),'Neutre')==1
and I test my script before the add of your line
num_ess = num_ess(num_ess >= 30 & num_ess <= 48);
and everything was ok before that ...
Walter Roberson
2015년 7월 19일
Okay, so comment out that change of mine, rewrite the resulting version using ismember() and so on, and then uncomment the line and test the resulting code.
Alexandre Williot
2015년 7월 19일
I try something like this but in final I lost information about my 'code_indice'. Is it possible just te redefine the size of matrix num,txt,raw before?
for essai = 1:length (nb_essai)
% for essai = 1:length (nb_essai)
num_ess = [];
num_ess = find (num(:,24) == essai);
%num_ess = num_ess(num_ess >= 30 & num_ess <= 48);
Val_CursX_ess = num(num_ess,6);
Val_CursY_ess = num(num_ess,7);
Val_Quest_ess = txt(num_ess,36);
Val_Indice_ess = txt(num_ess,40);
Val_Valid_ess = txt(num_ess,33);
% pause
%== boucle Question ==
for ques = 1:2
Question_interet = Type_Questions{ques};
[pos_question, index] = ismember ('Semantique', Val_Quest_ess);
%pos_question = find(strcmp(Question_interet,Val_Quest_ess) == 1);
Val_CursX_ess_Quest = Val_CursX_ess(pos_question,1);
Val_CursY_ess_Quest = Val_CursY_ess(pos_question,1);
Val_Quest_ess_Quest = Val_Quest_ess(pos_question,1);
Val_Indice_ess_Quest = Val_Indice_ess(pos_question,1);
Val_Valid_ess_Quest = Val_Valid_ess(pos_question,1);
if ques == 1
pos_ok = [];
[pos_ok, index] = ismember ('Emotion', Val_Quest_ess);
%pos_ok = find(strcmp('Semantique',Val_Indice_ess_Quest) == 0);
Val_Indice_ess_Quest = Val_Indice_ess_Quest(pos_ok,1);
Val_CursX_ess_Quest = Val_CursX_ess_Quest(pos_ok,1);
Val_CursY_ess_Quest = Val_CursY_ess_Quest(pos_ok,1);
Val_Quest_ess_Quest = Val_Quest_ess_Quest(pos_ok,1);
Val_Valid_ess_Quest = Val_Valid_ess_Quest(pos_ok,1);
% faut dégager les semantiques et conserver le reste
% --> créer un nouveau Val_Indice_ess_Quest
end
%-- Etat Indice -- Emo ou Neutre? --
% Code_Indice --> 1 pour Neutre
% Code_Indice --> 2 pour Emo
if strcmp(Val_Indice_ess_Quest(1,:),'Neutre')==1
code_Indice = 1;
elseif strcmp(Val_Indice_ess_Quest(1,:),'Emo')==1
code_Indice = 2;
else
code_Indice = 999;
end
if strcmp(Val_Valid_ess_Quest(1,:),'valide')==1
code_Vald = 1;
elseif strcmp(Val_Valid_ess_Quest(1,:),'invalide')==1
code_Vald = 2;
else
code_Vald = 999;
end
Alexandre Williot
2015년 7월 19일
Maybe, it could be easier if I join the script and a file for run the script for my data
이 질문은 마감되었습니다.
참고 항목
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)