이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to iterate cell array?
조회 수: 23 (최근 30일)
이전 댓글 표시
Majid
2023년 2월 26일
hello !
i have a cell array N1 (100x1),attached here, i want to do 51 iteration for each element of N1(each matrix).
knowing that N1 was saved and i just load it.
i tried with different method but always the same error
for i = 1:51
i = i+1
for itr = 1:100 %number of iteration is the size of my cell array
N = all_N1{i,itr}; % here is error " Index in position 2 exceeds array bounds. Index must not exceed 1."
%...............code
end
end
any help is appreciated!
답변 (3개)
Walter Roberson
2023년 2월 26일
You say that N1 is 100 x 1.
You have iter = 1:100 so on the second round, iter will become 2.
You have all_N1{i,iter} but iter has become 2 on the second iteration. But your cell array is 100 x 1 so there is no second column. Not unless you assigned into all_N1{:,2} inside the for i loop.
댓글 수: 2
Majid
2023년 2월 26일
@Walter Roberson N1 is already saved , i'm searching for a solution that makes me execute each matrix of N1 for 51 iterations
Walter Roberson
2023년 2월 26일
N1 is already saved as 100 x 1. When your for itr becomes 2, you attempt to access all_N1{i,iter} which would be all_N1{i,2} . If N is the same thing as all_N1 then you have a problem.
VBBV
2023년 2월 26일
편집: VBBV
2023년 2월 26일
for i = 1:51
for itr = 1:100 %number of iteration is the size of my cell array
N = all_N1{itr,i}; % switch position of indices.
end
end
As you say, N1 is of size 100x1, you need to switch the position of indices in the inner for loop as above. Also, you don't require to increment the outer for loop index, as this will cause the index to exceed out of bounds i.e. > 51 end
댓글 수: 3
VBBV
2023년 3월 3일
clear all % add this at the beginning of code
M = {rand(100,1)} % some data
M = 1×1 cell array
{100×1 double}
N1 = repmat(M,100,1) %each N1 is 100 x 1
N1 = 100×1 cell array
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
{100×1 double}
all_N1 = repmat(N1,1,51) % assuming all N1
all_N1 = 100×51 cell array
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
{100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double} {100×1 double}
for i = 1:51 %
for itr = 1:100 %number of iteration is the size of my cell array
N = all_N1{itr,i}; %
end
end
N
N = 100×1
0.7226
0.0332
0.8978
0.6621
0.7076
0.5424
0.5816
0.2112
0.2799
0.7556
Its unlikely you would get such error, Can you check whether you cleared all variables in your workspace ?each time you begin to run code, otherwise the workspace variables get populated and exceed the array dimensions,
Rik
2023년 3월 4일
Why suggest clear all? Using a function would also provide a clean slate.
Note that clear or clearvars should be preferred, as clear all clears much more. It is almost equivalent to restarting Matlab every time you run the code.
Torsten
2023년 2월 26일
all_N1 = cell(51,1);
% Generate 100 matrices of size 20x20 and save them in cell array
for i = 1:100
all_N1{i} = rand(20);
end
% Use the matrices in iterations
for i = 1:100
M = all_N1{i};
for iter = 1:51
% do something with the matrix M
end
end
댓글 수: 29
Majid
2023년 2월 26일
@Torsten you will find attached N1 , you will see 100 iterations , you will find a matrix in each one.
i want to do 51 iterations for each matrix in N1.
step = load('all_N1.mat');
all_N1 = step.all_N1;
for iter = 1:100
for i = 1 : 51
N = all_N1{i,iter};
%my code
end
end
it doesn't work.
Walter Roberson
2023년 2월 26일
step = load('all_N1.mat');
all_N1 = step.all_N1;
for iter = 1:100
this_N = all_N1{iter};
for i = 1 : 51
N = this_N;
%my code
end
end
this now does 51 iterations with the same array for each iteration. It is not clear why this would be desired.
Majid
2023년 2월 26일
i want to iterate each matrix in N1 for 51 iterations, it works for just one iteration without loop
Torsten
2023년 2월 27일
편집: Torsten
2023년 2월 27일
So you mean:
step = load('all_N1.mat');
all_N1 = step.all_N1;
all_N1_iter = cell(100,51);
for iter = 1:100
this_N = all_N1{iter};
all_N1_iter{iter,1} = this_N;
for i = 2 : 51
% do something with the matrix this_N
all_N1_iter{iter,i} = result of iteration i;
end
end
?
Rik
2023년 2월 27일
Then what you wrote didn't actually depend on i. Since you didn't show that code we can't explain to you why.
Majid
2023년 2월 27일
@Rik here is the needed part of the code , i can't show all code because it is complicated and you will not understand the coherence between different parts.
step1 = load('all_N1.mat');
all_N1 = datastrcut1.all_N1;
for iter = 1:100 % size of N1
for f_in = 0:50 % this a variable that i will use in my code
i = f_in+1;
N = all_N1{iter}; % i will start to execute each matrix of N1 noted N
% in my code i just have to use N
%% my code which is depended on N and f_in
%% my constraints
[[MyResult{i, iter},fval{i,iter}]= solve(prob) %here i want to solve my problem
end
end
my code with only one iteration of N , without loop, works well, but i want to run my code for a number of iterations, so i saved my variable matrix N for 100 iterations, and i tried to solve my problem for each one of them.
Rik
2023년 2월 27일
And where exactly are you storing the results back to all_N1? You have not really shown that your code depends on the value of i, but if you say that the result is the same, then apparently it doesn't.
Note that this can happen due to the inherent nature of the problem:
A = ones(1,4);
for n=1:numel(A)
A(n) = 1-(n/n); % code clearly depends on n
end
disp(A) % result is the same for each value of n
0 0 0 0
Rik
2023년 2월 27일
You don't have 51 columns, you only have one. You can duplicate your data, but then the results will be identical. What are you trying to do? That is the most important question here. In the code of your previous comment, your calculations do not actually depend on the value of i or f_in.
Majid
2023년 2월 27일
@Rik if you have seen attached my matrices in all_N1, these are refers to N for each iteration(because N is randomly generated).
My calculation is depended on f_in and i, because each result is represented as a function of (i) and (iter).
for e.g my first matrix N of size(300x3600) will be exectued for 51 iterations,
for f_in = 1 , f_in = 2, f_in = 3, ..... , f_in = 50. As a result i will get fval = 51x1 (here for one iteration )
for 100 iterations fval will be 51x100.
the number of iteration "100" is refers to all_N1, it means the iteration 1, the first matrix will be executed .
In the second iteration , the second matrix, until complete the 100 matrices of all_N1.
Rik
2023년 2월 27일
So then you end up with an array of 100x51 elements for fval. I still don't get what your problem is. You have a cell array with 100 elements. Each of those elements will result in 51 output values based the value of f_in. The indexing is now fixed, but your complaint that all columns contain the same data isn't.
Is that indeed what remains of this problem?
Majid
2023년 2월 27일
each column of 100 contains the same data in 51 rows, it is like i did 51 iterations for just "one f_in" however the data in each row should be changed.
Torsten
2023년 2월 27일
[[MyResult{i, iter},fval{i,iter}]= solve(prob)
Doesn't [[ throw an error ?
My guess is that you either solve the same problem 51 times or that all your 51 problems have the same solution.
Torsten
2023년 2월 27일
step = load('all_N1.mat');
all_N1 = step.all_N1;
all_N1_copied = cell(size(all_N1,1),51);
for i = 1:size(all_N1,1)
for j = 1:51
all_N1_copied_51_times{i,j} = all_N1{i};
end
end
Rik
2023년 2월 27일
You're proposing to copy your data, but that will get you the same results.
How are you making sure that a different value of f_in will result in a different output? It seems to me that the only code that was relevant is the code you removed.
Majid
2023년 2월 27일
Rik
2023년 2월 27일
You told us you didn't show all code because it would be confusing, which is fine.
What you should do is this:
output = cell(numel(all_N1),1)
for iter = 1:numel(all_N1) % size of N1
for f_in = 0:50 % this a variable that i will use in my code
i = f_in+1;
output{iter,i} = YourCustomFunction(all_N1{iter},f_in);
end
end
function output = YourCustomFunction(N,varargin)
% Here you can put all your other code
end
This way you can really isolate everything. This way you can make 100% sure that your code depends only on the data for 1 iteration. You can add inputs and outputs as needed, but you should not put anything else inside the loops.
Rik
2023년 3월 2일
Then you know that your code doesn't actually depend on the value of f_in. Just like the code I posted previously:
A = ones(1,4);
for n=1:numel(A)
A(n) = 1-(n/n); % code clearly depends on n
end
disp(A) % result is the same for each value of n
0 0 0 0
That isn't bad, it is what it is. But no matter how you package and compartmentalize your code, this will be the case. If you expected something else there are two options: either your expectations are wrong, or your code is wrong. Since you have posted neither, it is fully up to you to decide which it is. But at least now you know. If you share your implementation of YourCustomFunction, we might be able to help you find out why the result doesn't depend on f_in.
Majid
2023년 3월 2일
편집: Majid
2023년 3월 2일
@Rik i tried with different cases but the same result is given. i don't know where is the problem so in the loop for f_in or loop for N.
i transformed f_in into cell in order to use element by element but nothing has changed.
there is a one solution that may works, i will change my all_N1 into matrices and i apply the loop for just for f_in
Rik
2023년 3월 3일
If you did as you claimed, the problem is not in any of the loops.
You need to share your implementation of Your Custom Function, otherwise there is no point in responding.
Rik
2023년 3월 3일
So you didn't do what I suggested. Why exactly didn't you do that? You should have implemented it something like I did below.
% Load data from mat file
step = load('all_N1.mat');
all_N1 = step.all_N1;
% Prepare output parameters
MyResult = cell(1,numel(all_N1));
fval = cell(1,numel(all_N1));
for iter = 1:numel(all_N1)
for f_in = 0:50
i = f_in+1;
% Run solver
[MyResult{i,iter},fval{i,iter}, exitflag] = YourCustomFunction(all_N1{iter},f_in);
% Overwrite fval when solver fails.
if exitflag<=0
fval{i,iter}=-inf;
end
end
end
function [MyResult,fval,exitflag] = YourCustomFunction(N,f_in)
S = optimvar("S",[M,1],"Type","integer","LowerBound",0,"UpperBound",1);
obj = fcn2optimexpr( @Objective_function ,S);
prob = optimproblem('ObjectiveSense','max');
prob.Objective = obj ;
constr1 = S <= Q./sum(fcn2optimexpr( @Myconstraint1, q_int),2 );
constr2 = cumsum(S.*(sum(Energy_Pr,2))) <= E_max(1)-E_prop;
prob.Constraints.constr1 = constr1;
prob.Constraints.constr2 = constr2;
[MyResult,fval, exitflag] = solve(prob);
end
Now you need to show me where exactly you're using f_in (or even N). I only see M, along with some undefined variables and functions you haven't shared.
Do you see how this helps defining the problem? Do you also notice how the part with the fewest comments is the part that is causing the issue? That should tell you something.
Rik
2023년 3월 3일
Ok, now you replaced q_int with f_in. That helps, but since it still doesn't use N, I doubt that actually solves the problem.
I would suggest you write a complete implementation of YourCustomFunction. Don't edit any of the rest of my code. Only that function. You can add extra output variables if you need to, but do not change anything else. That will help you narrow down what actually is going on.
Some problems are just too big to fit in your head at the same time. That happens to me all the time. That is why I split up big problem into smaller ones. I'm not smart enough to solve 1 big problem, but I can generally manage to solve 20 smaller ones.
Majid
2023년 3월 3일
@Rik i already did your provided code and it gives the same results,i have a lot of function so i can't share all of them.
I have solved my problem for a fixed value of f_in , now i want to execute the program for all possible f_in (from 0 to 50).
Because i have random variables, each iteration new size of N is generated, to avoid this case,i will use saved N in order to fix them over the loop of f_in
Rik
2023년 3월 3일
I'm sorry, I'm out. I can't help you if you refuse to follow my advice for troubleshooting.
I hope fo you someone else will be able to pick up this thread, but I'm out.
If you change your mind you can attach the relevant m files and show your implementation of YourCustomFunction.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
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 (한국어)
