필터 지우기
필터 지우기

how i can fix this error?

조회 수: 2 (최근 30일)
Armina Petrean
Armina Petrean 2023년 5월 23일
댓글: Dyuman Joshi 2023년 5월 24일
i had this code and i don't understand what is rong. i have a text and i want to extract the words in it. and it gives me this error.

답변 (3개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 5월 23일
As shown in your screenshot, fix these errors:
% Err 1
text_analiza = [rezultat_ascii_corpus; 32;32;32 ...]
%% Must be
text_analiza = [rezultat_ascii_corpus; 32;32;32];
% Err2
i==1;
j==1;
% must be
i=1;
j=1;
% it is not shown in your screenshot, but looks like
while
end % might be missing

Walter Roberson
Walter Roberson 2023년 5월 23일
i == 1;
would attempt to look for a variable named i and if it were found, then it would attempt to compare each element of i to 1, constructing a boolean array the same size as i as the result. The value is not being assigned to a variable so the resulting array would be assigned to the internal variable named ans . Then because of the semi-colon the result would be discarded (not displayed.)
If no variable named i were found, MATLAB would proceed to look for a function named i and if it found such a function, MATLAB would try to invoke the function with no parameters, and then try to compare the result to 1 and so on. MATLAB happens to have a built-in function named i which returns sqrt(-1) .
Likewise for the j == 1 line -- and MATLAB also happens to have a function named j which also returns sqrt(-1) .
Well... that is what would happen if you did not have a mistake earlier in the code. You have
text_analiza = [rezultat_ascii_corpus;32;23;32; ...];
In MATLAB, when you have the ... characters then everything from the ... to the result of the line is treated as a comment, and MATLAB expects the next line to be a continuation. So the ] on the line is just a comment, same as if you had done
text_analiza = [rezultat_ascii_corpus;32;23;32; ... %];
so you are in a situation where you have an active [ so you are building a list. And i==1 and j==1 happen to be valid expressions for contributing to a list being built. But while is a keyword that cannot exist inside an attempt to use [] to build a list, so MATLAB complains about the while
Your fundamental mistake is that you do not have a ] closing the [ that you started.
  댓글 수: 6
Walter Roberson
Walter Roberson 2023년 5월 23일
You fopen() a file, but you do not store the resulting file identifier, and you do not use the file identifier to read anything; you also do not close the file identifier.
You do not initialize rezultat_ascii_corpus
The
i == 1;
j == 1;
are unlikely to be what you want. You almost certainly want assignment statements there, not comparison statements.
Walter Roberson
Walter Roberson 2023년 5월 23일
By the way: you may wish to consider using
cuvinte = regexp(text_analiza, ' +', 'split');
instead of your loops.

댓글을 달려면 로그인하십시오.


Dyuman Joshi
Dyuman Joshi 2023년 5월 23일
@Armina Petrean, keep in mind that posting the picture of the code is not helpful. Even if we suggest a solution, it is not guaranteed to work because the suggestion is not the best because of limited information.
Copy - pasting the code or attaching it via the paperclip button makes it easier for us to help you.
Secondly, the 7th line of your code, where you define the variable "text_analiza", is incomplete, as you have used the three dots, "...", called ellipses. When you use this, MATLAB expects the code to continue in the next line.
But instead of continuing the code, by defining a numeric array, the next line is different. Essentially, you have defined the while loop inside the variable, which is not allowed, and thus gives the error.
%Incomplete statement
y = [1 2 3 ...]
i==1;
j==1;
while i+j<5
Illegal use of reserved keyword "while".
i=i+j;
end
It's not clear as to how you want to define "text_analiza", so it is difficult to suggest anything.
Additionally, use single '=' sign if you want to assign value to any variable.
  댓글 수: 3
Armina Petrean
Armina Petrean 2023년 5월 23일
for unique words= cuvinte unice
Dyuman Joshi
Dyuman Joshi 2023년 5월 24일
After making changes, does this code work?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by