Error: File: Parallelanalysis.m Line: 60 Column: 1 This statement is not inside any function.
이전 댓글 표시
Line 60, T2 variable is giving an error and I don't think this should be insie any function. Does anyone know where this needs to be or if not does it need to be removed?
댓글 수: 2
Ahash Thayalan
2022년 11월 5일
Steven Lord
2022년 11월 5일
If you have the file open in the MATLAB Editor, select all the text then right-click and select "Smart Indent" from the context menu. Once you've done that, scroll to the bottom of the file. If you click on an end keyword MATLAB by default will highlight the keyword with which that end is associated.
If you click on the last end MATLAB will show it crossed out, indicating it doesn't match with anything. If you click on the end on line 57 (the one with the comment "end time loop") MATLAB will show that matches the function keyword on line 1. Therefore the call to toc on the next line is not part of the function and could never be executed. As such, MATLAB knows that there is an error somewhere and so throws an error.
So you likely have either one extra end that you don't need or you are missing the start of an if, for, while, etc. statement.
답변 (1개)
Walter Roberson
2022년 11월 5일
end % end time loop
What time loop? You are not inside any loop there. The parfor already ended.
댓글 수: 7
Ahash Thayalan
2022년 11월 5일
Ahash Thayalan
2022년 11월 5일
Walter Roberson
2022년 11월 5일
for idx = [1, 2, 4, 5, 6, 7, 8]
HourlyData(DataLayer,:,:) = ncread(FileName, Contents.Variables(idx).Name,...
[StartLon, StartLat, idxTime], [NumLon, NumLat, 1]);
DataLayer = DataLayer + 1;
end
The loop in that code is complete; there is no need for another end statement to terminate it. And besides, the end time loop statement is in a different function completely; you cannot start a loop in one function and end it in a different function.
Ahash Thayalan
2022년 11월 6일
Walter Roberson
2022년 11월 6일
idxTime is used several times in that function but is not defined in that context.
When you define a variable in a function and then call a second function, then the variable does not get defined in the second function — except, that is, for the case where the second function is a nested function that is defined within the first function.
Ahash Thayalan
2022년 11월 6일
Walter Roberson
2022년 11월 6일
You have several choices:
- You can pass idxTime to Parallelanalysis in your function calls;
- You can construct Parallelanalysis as a nested function inside ParallelProcessing.m, at some point after the idxTime variable has been assigned to (such as at the end of the file), so that idxTime would become a shared variable. For this, the code currently in Parallelanalysis.m would have to be moved to be inside ParallelProcessing.m . I am not certain at the moment whether parfor will accept this possibility
- You can use one of the techniques described at http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F to share variables with the code. However, this will be tricky, as parfor starts the routine in a different process that does not have access to global variables... you might possibly not be able to get any of these techniques to work with parfor
- You can use a pair of parallel.pool.DataQueue so as to send the current value of idxTime to the workers
- Instead of using parfor you could use parfeval() and pass idxTime to the function. The function would have to expect to receive it as a parameter
- Instead of using parfor, you could open the pool once and keep it open, and at the point where you would normally use parfor, you would use parfevalOnAll() to send the current value of idxTime to every worker, followed by using parfeval() to create the tasks
The only one of these that I recommend is the first, making idxTime a parameter to the function.
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!