Why openmodelica give me this array dimension error? - modelica

I'm developing a system in modelica and i have a big problem.
When i run the simulation in terminal, it display this error:
"Dimension 2 has bounds 1...3, got array subscript 0".
I suppose that an array declaration have an index out of bound, but no one of them have it. I don't know what to do. I'll leave the code here, i hope someone can help me
https://github.com/BigMautone/Drones.git
probably, the error is located in psoControllor.mo or drone.mo or collisionAvoidance.mo or System.mo

Related

How to use a FOR loop in a 'struct' subindex? - MATLAB

I have a struct as shown in picture, and I need to address one of the columns in a FOR loop, as shown. But I keep getting this error:
Function 'subsindex' is not defined for values of class 'struct'.
Error in analisa_arx_teste (line 351)
In my case, what i want is :line 1 represents i = 1, line 2 i =2; So, for features, When I ask for pref_estemod(i).features is to get the values from the field features associated to each model.
I am just starting programming with matlab, so all your help would be appreciated.
Thanks!
for i=pref_estemod(1:npreferred)
[m,n]=size(Training);
features=(pref_estemod(1,i).features);
end
The error lies in i=pref_estemod(1:npreferred).
If you intend to use i for indexing, the syntax is for i=1:npreferred.
1:npreferred itself expands to the horizontal array [1,2,...,npreferred]. = with a leading for is a special syntax combination. It means do the following code with i=1, i=2, ..., i=npreferred. Now I am sure you already know the idea behind for loop. The reason I write all this is to give you the following warning/advise. Do NOT expect the same syntax to work with non-numeric arrays. Because it works in some cases and not others.

Unable to use "range" function in MATLAB

I need the range of a vector. From the MATLAB documentation, it says "For vectors, range(x) is the range of the elements." However, whenever I try to use it, I get the error "Undefined function 'range' for input arguments of type 'double'." For example, if I use x=[1 2 3 4 5] and then do range(x), I will get this error. Am I crazy or is MATLAB screwing up here? I'm usually pretty good at figuring things out on my own but this one is stumping me.

MATLAB Index exceeds matrix dimensions in programming for explicit euler

I keep getting this error. I received this error after I corrected for logical integer error. The only way I could think of programming this was defining the initial value and then start euler's method at the next t value since it uses the previous solution to find the next one. But by doing this I am getting this error? I'm unsure how to fix it. I tried to end one step from my final value but that didn't work either. Thanks for the help. For the problem we had to create the function and call it. I was initially using n=8.
function [exeuler] = pb3(n)
%using explicit euler to solve ODE with input n and outputting exeuler as
%the answer
%n=steps t,y are initial conditions
h=3/n;
t=logical((1+h):h:4);
back=logical(t-h);
exeuler(1)=2; %defines the initial value
exeuler(t)=exeuler(back)+h*(t.^2-(2*exeuler(back)/t));
end
Well, I am sorry, but you haven't showed much of effort. For the future, please provide the complete code (i.e. with example function and so on). This is very unclear.
I think your problem is in these lines:
t=logical((1+h):h:4);
exeuler(t)=exeuler(back)+h*(t.^2-(2*exeuler(back)/t));
cause t is a vector. You are calling vector with non-integer values as index. Then, I guess, you get the wrong amount of exeuler(t)'s which leads to the error.
And for-loop is missing, isn't it? Because you don't use the Euler method stepwise andd therefore f(t+1) doesn't really depend on f(t).
So, my advice in general would be not to correct this error, but to rethink your algorithm.

Grouping variable must be a vector or a character array

I have done the following:
I=imread('image.png');
I2=im2double(I);
cidx = fcm(I2,5);
When I tried running the following command:
silhouette(I2,cidx)
I got the following error:
Error using grp2idx (line 39)
Grouping variable must be a vector or a character array.
Error in silhouette (line 79)
[idx,cnames] = grp2idx(clust);
How can I solve this issue?
Thanks.
With problems like this, you want to work backwards through the errors. It states
Grouping variable must be a vector or a character array.
and obviously it is the variable clust that it is complaining about. So look at the file silhouette, and figure out what the variable clust is set to. I am imagining it is not a vector…
When you turn on the debugger to stop on error, you will be "in the function" where the error occurs and then you can examine the variables, move up and down the stack, and figure out exactly what went wrong.
If you still need more help, let us know what you got when you typed
whos clust
in the context of silhouette.

keving murphy's hmm matlab toolbox assertion error

I am working on a project that needs to use hidden markov models. I downloaded Kevin Murphy's toolbox. I have some problems about the usage. In the toolbox webpage, he says that first input of dhmm_em and dhmm_logprob are symbol sequence data. On their examples, they give row vectors as data. So, when I give my symbol sequence as row vector, I get error;
??? Error using ==> assert at 9
assertion violated:
Error in ==> fwdback at 105
assert(approxeq(sum(alpha(:,t)),1))
Error in ==> dhmm_logprob at 17
[alpha, beta, gamma, ll] = fwdback(prior,
transmat, obslik, 'fwd_only', 1);
Error in ==> mainCourseProject at 110
loglik(train_act) =
dhmm_logprob(orderedSymbols,
hmm{train_act}.prior,
hmm{train_act}.trans,
hmm{act}.emiss);
However, before giving this error, code works for some symbol vectors. When I give my data as column vector, functions work fine, no errors. So why exactly am I getting this error?
You might say that I should be giving not single vectors, but vector sets, I also tried to collect my feature vectors in a struct and give row vectors as such, but nothing changed, I still get assertion error.
By the way, my symbol sequence does not have any zeros, I am doing everything almost the same as they showed in their examples, so I would be greatful if anyone could help me please.
Im not sure, but from the function call stack shown above, shouldn't the last line be hmm{train_act}.emiss instead of hmm{act}.emiss.
In other words when you computing the log-probability of a sequence, you should pass components that belong to the same HMM model (transition matrix, emission matrix, and prior probabilities).
By the way, the ASSERT in the code is a sanity check that a vector of probabilities should sum to 1. Oftentimes, when working with very small values (log-probabilities), numerical stability issues can creep in... You could edit the APPROXEQ function to relax the comparison a bit, by giving it a bigger margin of error
This error message and the code it refers to are human-readable. An assertion is a guard put in by the programmer, to ensure that certain conditions are met. In this case, what is the condition? approxeq(sum(alpha(:,t)),1) I'd venture to say that approxeq wants the values to be approximately equal, so this boils down to: sum(alpha(:,t)) ~= 1
Without knowing anything about the code, I'd also guess that these refer to probabilities. The probabilities of a node's edges must sum to one. Hopefully this starts you down a productive debugging path. If you can't figure out what's wrong with your input that produces this condition, start wading into the code a bit to see where this alpha vector comes from, and how it ended up invalid.