Category: Matlab
Category Archives: Matlab
Understanding using the Plot() and troubleshooting with R2024a
So I am doing a simple project coupling with Simulink and an Arduino Uno. I built a model and used the arduino to generate data.
This is the code that I am using.
figure; plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
eo_act and ei are variables.
Ts is the assigned Sample time which is declared in the program in Simulink.
40 is the amount of time the program ran to collect the data.
So my problem is this: I keep on having this error code. But I don’t know how to fix it or understand why it is popping up.
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,’r’);
and
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
I read the doc file assoiated with plots(), but it doesn’t seem to explain for my situation. I have been experimenting with it. I separated each variable in their own respective plot()s and added a "hold on". It still throws the same error. I also verified that the variable has data in them.So I am doing a simple project coupling with Simulink and an Arduino Uno. I built a model and used the arduino to generate data.
This is the code that I am using.
figure; plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
eo_act and ei are variables.
Ts is the assigned Sample time which is declared in the program in Simulink.
40 is the amount of time the program ran to collect the data.
So my problem is this: I keep on having this error code. But I don’t know how to fix it or understand why it is popping up.
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,’r’);
and
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
I read the doc file assoiated with plots(), but it doesn’t seem to explain for my situation. I have been experimenting with it. I separated each variable in their own respective plot()s and added a "hold on". It still throws the same error. I also verified that the variable has data in them. So I am doing a simple project coupling with Simulink and an Arduino Uno. I built a model and used the arduino to generate data.
This is the code that I am using.
figure; plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
eo_act and ei are variables.
Ts is the assigned Sample time which is declared in the program in Simulink.
40 is the amount of time the program ran to collect the data.
So my problem is this: I keep on having this error code. But I don’t know how to fix it or understand why it is popping up.
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,’r’);
and
Error using plot
Data cannot have more than 2 dimensions.
Error in RCPulseM (line 76)
plot(0:Ts:40,eo_act,0:Ts:40,ei,’r’);
I read the doc file assoiated with plots(), but it doesn’t seem to explain for my situation. I have been experimenting with it. I separated each variable in their own respective plot()s and added a "hold on". It still throws the same error. I also verified that the variable has data in them. plot MATLAB Answers — New Questions
Compensate the vector with the last entry
I have a length L vector contains some numbers, I want to compensate this vector to length K, where K > L, with repeating the last entry of the vector. For example, the vector is [2 4 7 3], after compensate, it will be [2 4 7 3 3 3 3 3]. I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate.
Thanks,I have a length L vector contains some numbers, I want to compensate this vector to length K, where K > L, with repeating the last entry of the vector. For example, the vector is [2 4 7 3], after compensate, it will be [2 4 7 3 3 3 3 3]. I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate.
Thanks, I have a length L vector contains some numbers, I want to compensate this vector to length K, where K > L, with repeating the last entry of the vector. For example, the vector is [2 4 7 3], after compensate, it will be [2 4 7 3 3 3 3 3]. I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate.
Thanks, matlab MATLAB Answers — New Questions
Live Editor (Matlab Mobile): clear output
Hi! How can I clear all outputs in Matlab Mobile when using the Live Editor environment?Hi! How can I clear all outputs in Matlab Mobile when using the Live Editor environment? Hi! How can I clear all outputs in Matlab Mobile when using the Live Editor environment? matlab mobile, live editor MATLAB Answers — New Questions
Why does my parpool crash when I am running Python from within MATLAB using Anaconda Python?
My parallel pool keeps crashing every time I run my MATLAB code that calls Python functions inside it. My Python installation was installed using Anaconda.
My crash log is shown below:
——————————————————————————–
abort() detected at 2023-11-06 14:11:56 -0800
——————————————————————————–
Stack Trace (captured):
[ 0] 0x00007ffcdc43aca3 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00044195 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffcdc439278 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00037496 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffcdc43d39f C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00054175 foundation::core::diag::symbols::getSymbolAddress+00009455
[ 3] 0x00007ffcdc4403b7 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00066487 foundation::core::diag::is_terminate_message_enabled+00000535
[ 4] 0x00007ffc891a5e6f C:Program FilesMATLABR2023bbinwin64mcr.dll+00876143 mnFullExitFcn+00036351
[ 5] 0x00007ffc891a569d C:Program FilesMATLABR2023bbinwin64mcr.dll+00874141 mnFullExitFcn+00034349
[ 6] 0x00007ffc891a1523 C:Program FilesMATLABR2023bbinwin64mcr.dll+00857379 mnFullExitFcn+00017587
[ 7] 0x00007ffc891a322f C:Program FilesMATLABR2023bbinwin64mcr.dll+00864815 mnFullExitFcn+00025023
[ 8] 0x00007ffd2aa61881 C:WINDOWSSystem32ucrtbase.dll+00465025 raise+00000481
[ 9] 0x00007ffc0d6268d3 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00747731 _kmp_get_reduce_method+00026275
[ 10] 0x00007ffc0d606a1c C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00616988 kmp_set_affinity+00005292
[ 11] 0x00007ffc0d625d2d C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00744749 _kmp_get_reduce_method+00023293
[ 12] 0x00007ffc0d612515 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00664853 _kmp_acquire_nested_drdpa_lock+00021861My parallel pool keeps crashing every time I run my MATLAB code that calls Python functions inside it. My Python installation was installed using Anaconda.
My crash log is shown below:
——————————————————————————–
abort() detected at 2023-11-06 14:11:56 -0800
——————————————————————————–
Stack Trace (captured):
[ 0] 0x00007ffcdc43aca3 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00044195 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffcdc439278 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00037496 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffcdc43d39f C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00054175 foundation::core::diag::symbols::getSymbolAddress+00009455
[ 3] 0x00007ffcdc4403b7 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00066487 foundation::core::diag::is_terminate_message_enabled+00000535
[ 4] 0x00007ffc891a5e6f C:Program FilesMATLABR2023bbinwin64mcr.dll+00876143 mnFullExitFcn+00036351
[ 5] 0x00007ffc891a569d C:Program FilesMATLABR2023bbinwin64mcr.dll+00874141 mnFullExitFcn+00034349
[ 6] 0x00007ffc891a1523 C:Program FilesMATLABR2023bbinwin64mcr.dll+00857379 mnFullExitFcn+00017587
[ 7] 0x00007ffc891a322f C:Program FilesMATLABR2023bbinwin64mcr.dll+00864815 mnFullExitFcn+00025023
[ 8] 0x00007ffd2aa61881 C:WINDOWSSystem32ucrtbase.dll+00465025 raise+00000481
[ 9] 0x00007ffc0d6268d3 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00747731 _kmp_get_reduce_method+00026275
[ 10] 0x00007ffc0d606a1c C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00616988 kmp_set_affinity+00005292
[ 11] 0x00007ffc0d625d2d C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00744749 _kmp_get_reduce_method+00023293
[ 12] 0x00007ffc0d612515 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00664853 _kmp_acquire_nested_drdpa_lock+00021861 My parallel pool keeps crashing every time I run my MATLAB code that calls Python functions inside it. My Python installation was installed using Anaconda.
My crash log is shown below:
——————————————————————————–
abort() detected at 2023-11-06 14:11:56 -0800
——————————————————————————–
Stack Trace (captured):
[ 0] 0x00007ffcdc43aca3 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00044195 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffcdc439278 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00037496 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffcdc43d39f C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00054175 foundation::core::diag::symbols::getSymbolAddress+00009455
[ 3] 0x00007ffcdc4403b7 C:Program FilesMATLABR2023bbinwin64libmwfl.dll+00066487 foundation::core::diag::is_terminate_message_enabled+00000535
[ 4] 0x00007ffc891a5e6f C:Program FilesMATLABR2023bbinwin64mcr.dll+00876143 mnFullExitFcn+00036351
[ 5] 0x00007ffc891a569d C:Program FilesMATLABR2023bbinwin64mcr.dll+00874141 mnFullExitFcn+00034349
[ 6] 0x00007ffc891a1523 C:Program FilesMATLABR2023bbinwin64mcr.dll+00857379 mnFullExitFcn+00017587
[ 7] 0x00007ffc891a322f C:Program FilesMATLABR2023bbinwin64mcr.dll+00864815 mnFullExitFcn+00025023
[ 8] 0x00007ffd2aa61881 C:WINDOWSSystem32ucrtbase.dll+00465025 raise+00000481
[ 9] 0x00007ffc0d6268d3 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00747731 _kmp_get_reduce_method+00026275
[ 10] 0x00007ffc0d606a1c C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00616988 kmp_set_affinity+00005292
[ 11] 0x00007ffc0d625d2d C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00744749 _kmp_get_reduce_method+00023293
[ 12] 0x00007ffc0d612515 C:UsersusernameAppDataLocalanaconda3Librarybinlibiomp5md.dll+00664853 _kmp_acquire_nested_drdpa_lock+00021861 python, anaconda3, parpool, crash, pyrunfile MATLAB Answers — New Questions
Issues in Running VBA macros programmatically from Matlab
Hello,
When I try to open my VBA macro enabled excel directly and run the macro within excel, it works fine. However, when I try to do the same operation using Matlab script, it shoots these error messages. Does anyone has any idea?
% Test Script VBA Code access and run
ExcelApp = actxserver(‘Excel.Application’); % Create object
ExcelApp.Visible = 1; % Show window (optional).
macrobook = ExcelApp.Workbooks.Open(fullfile(‘C:Pro’,’Test.xlsm’)); % Open file
retVal = ExcelApp.Run(‘Macro1’); % Run Macro1
I have checked my macro settings in excel and they are all enabled:
I have also attached a simple macro enabled file example.Hello,
When I try to open my VBA macro enabled excel directly and run the macro within excel, it works fine. However, when I try to do the same operation using Matlab script, it shoots these error messages. Does anyone has any idea?
% Test Script VBA Code access and run
ExcelApp = actxserver(‘Excel.Application’); % Create object
ExcelApp.Visible = 1; % Show window (optional).
macrobook = ExcelApp.Workbooks.Open(fullfile(‘C:Pro’,’Test.xlsm’)); % Open file
retVal = ExcelApp.Run(‘Macro1’); % Run Macro1
I have checked my macro settings in excel and they are all enabled:
I have also attached a simple macro enabled file example. Hello,
When I try to open my VBA macro enabled excel directly and run the macro within excel, it works fine. However, when I try to do the same operation using Matlab script, it shoots these error messages. Does anyone has any idea?
% Test Script VBA Code access and run
ExcelApp = actxserver(‘Excel.Application’); % Create object
ExcelApp.Visible = 1; % Show window (optional).
macrobook = ExcelApp.Workbooks.Open(fullfile(‘C:Pro’,’Test.xlsm’)); % Open file
retVal = ExcelApp.Run(‘Macro1’); % Run Macro1
I have checked my macro settings in excel and they are all enabled:
I have also attached a simple macro enabled file example. excel, macros MATLAB Answers — New Questions
can I use custom libraries (dlls) written for matlab with Thingspeak
I have developed some custom libraries (dlls written in C++) that I call and use in analysis using desktop Matlab.
Is there a way to use these libraries with thingspeak ?
Are there any alternatives or workarounds that would serve the same purpose.I have developed some custom libraries (dlls written in C++) that I call and use in analysis using desktop Matlab.
Is there a way to use these libraries with thingspeak ?
Are there any alternatives or workarounds that would serve the same purpose. I have developed some custom libraries (dlls written in C++) that I call and use in analysis using desktop Matlab.
Is there a way to use these libraries with thingspeak ?
Are there any alternatives or workarounds that would serve the same purpose. thingspeak, custom dlls, custom libraries MATLAB Answers — New Questions
VideoReader missing codec problem
I cannot open avi files with VideoReader on my MacBook (OS Ventura 13.5) with a pretty up-to-date version of MATLAB (R2023b; 23.2.0.2365128, 64-bit). When I try to open an avi file with the following code
v = VideoReader(vidFileName.avi)
I get the following error
Error using VideoReader/initReader
Unable to determine the required codec.
Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);
Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
Similarly, if I try to get information about the avi file, the code
info = mmfileinfo(vidFileName.avi)
returns the error
Unable to determine the required codec.
Some important points:
Yes, I know other people have posted similar problems. No clear solution to my problem is found there
Yes, this video file is valid and uncorrupted. It plays fine on VLC Player. It does not play on QuickTime, which does not support the avi format
Yes, I am aware that the solution might be "installing new codecs"–a solution mentioned in some other posts–but I need more information than that
Here’s the deal: The MATLAB Central "solutions" mention installing codecs from mediaplayercodecpack.com…but that only support Windows systems. I tried installing 3rd party Mac codecs from 3ivx.com, but they didn’t work. FWIW, they didn’t allow QT to play avi files either, as it was supposed to do. I know nothing about video codecs, but teh interwebs tell me they are usually stored in Library/QuickTime on Macs. Sure enough, the 3ivx installation did add "3ivxVideoCodec.component" to that folder, but again, it doesn’t work. The fact that VLC Player does work suggests that the necessary codec does exist somewhere on my Mac, but apparently MATLAB can’t use it.
In closing, I pose these fundamental questions: Doesn’t the MATLAB installation include the video codes required for the video formats VideoReader/VideoWriter supposedly supports? If yes, why am I getting this probelm? If no, where do I find the relevant codecs and how do I install them in a way that MATLAB can use?I cannot open avi files with VideoReader on my MacBook (OS Ventura 13.5) with a pretty up-to-date version of MATLAB (R2023b; 23.2.0.2365128, 64-bit). When I try to open an avi file with the following code
v = VideoReader(vidFileName.avi)
I get the following error
Error using VideoReader/initReader
Unable to determine the required codec.
Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);
Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
Similarly, if I try to get information about the avi file, the code
info = mmfileinfo(vidFileName.avi)
returns the error
Unable to determine the required codec.
Some important points:
Yes, I know other people have posted similar problems. No clear solution to my problem is found there
Yes, this video file is valid and uncorrupted. It plays fine on VLC Player. It does not play on QuickTime, which does not support the avi format
Yes, I am aware that the solution might be "installing new codecs"–a solution mentioned in some other posts–but I need more information than that
Here’s the deal: The MATLAB Central "solutions" mention installing codecs from mediaplayercodecpack.com…but that only support Windows systems. I tried installing 3rd party Mac codecs from 3ivx.com, but they didn’t work. FWIW, they didn’t allow QT to play avi files either, as it was supposed to do. I know nothing about video codecs, but teh interwebs tell me they are usually stored in Library/QuickTime on Macs. Sure enough, the 3ivx installation did add "3ivxVideoCodec.component" to that folder, but again, it doesn’t work. The fact that VLC Player does work suggests that the necessary codec does exist somewhere on my Mac, but apparently MATLAB can’t use it.
In closing, I pose these fundamental questions: Doesn’t the MATLAB installation include the video codes required for the video formats VideoReader/VideoWriter supposedly supports? If yes, why am I getting this probelm? If no, where do I find the relevant codecs and how do I install them in a way that MATLAB can use? I cannot open avi files with VideoReader on my MacBook (OS Ventura 13.5) with a pretty up-to-date version of MATLAB (R2023b; 23.2.0.2365128, 64-bit). When I try to open an avi file with the following code
v = VideoReader(vidFileName.avi)
I get the following error
Error using VideoReader/initReader
Unable to determine the required codec.
Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);
Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
Similarly, if I try to get information about the avi file, the code
info = mmfileinfo(vidFileName.avi)
returns the error
Unable to determine the required codec.
Some important points:
Yes, I know other people have posted similar problems. No clear solution to my problem is found there
Yes, this video file is valid and uncorrupted. It plays fine on VLC Player. It does not play on QuickTime, which does not support the avi format
Yes, I am aware that the solution might be "installing new codecs"–a solution mentioned in some other posts–but I need more information than that
Here’s the deal: The MATLAB Central "solutions" mention installing codecs from mediaplayercodecpack.com…but that only support Windows systems. I tried installing 3rd party Mac codecs from 3ivx.com, but they didn’t work. FWIW, they didn’t allow QT to play avi files either, as it was supposed to do. I know nothing about video codecs, but teh interwebs tell me they are usually stored in Library/QuickTime on Macs. Sure enough, the 3ivx installation did add "3ivxVideoCodec.component" to that folder, but again, it doesn’t work. The fact that VLC Player does work suggests that the necessary codec does exist somewhere on my Mac, but apparently MATLAB can’t use it.
In closing, I pose these fundamental questions: Doesn’t the MATLAB installation include the video codes required for the video formats VideoReader/VideoWriter supposedly supports? If yes, why am I getting this probelm? If no, where do I find the relevant codecs and how do I install them in a way that MATLAB can use? video, codec, mac, matlab MATLAB Answers — New Questions
Efficient management of interacting atoms based on their mutual distance
Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea?Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea? Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea? fast and efficient double counting of data MATLAB Answers — New Questions
See also … blocks viewing of answer
I’m trying to see an answer that includes a screenshot apparently. The See Also pane is blocking much of the screen so I can’t see what I need to see. How do I dismiss this part I don’t need?I’m trying to see an answer that includes a screenshot apparently. The See Also pane is blocking much of the screen so I can’t see what I need to see. How do I dismiss this part I don’t need? I’m trying to see an answer that includes a screenshot apparently. The See Also pane is blocking much of the screen so I can’t see what I need to see. How do I dismiss this part I don’t need? dismiss see also MATLAB Answers — New Questions
Path Following Algorithm Line-Circle Path Path Switching Problem
Hi everyone ,
I’m trying to implement a path following algorithm for UAV (Carrot Chase) with matlab for a line-circle path.
I have already implemented the algorithm for straight line and the loiter separately and this codes are work fine. But, since they are geometrically different shapes, they have different algorithms. So we need to switch algorithms when switching between these two shapes if we want to follow this two shapes together . And i added a algorithm for that but i think it’s not working
i have a variable for that named as " guidance index". You can see this variable at the begginning of the code. When i enter this variable 1 the UAV will follow the straight line path firstly. But if i enter this variable 2, the UAV will follow the circle firstly.
You can see this in the files I attached. But the real problem starts here. After the straight line path ends, it does not follow the circular path but goes out of the path. Likewise, when I set the guidance_index variable to 2, it follows the circle path correctly, but this time it does not continue with the straight line path.
How can i fix it ?
Thanks a lot.
Best RegardsHi everyone ,
I’m trying to implement a path following algorithm for UAV (Carrot Chase) with matlab for a line-circle path.
I have already implemented the algorithm for straight line and the loiter separately and this codes are work fine. But, since they are geometrically different shapes, they have different algorithms. So we need to switch algorithms when switching between these two shapes if we want to follow this two shapes together . And i added a algorithm for that but i think it’s not working
i have a variable for that named as " guidance index". You can see this variable at the begginning of the code. When i enter this variable 1 the UAV will follow the straight line path firstly. But if i enter this variable 2, the UAV will follow the circle firstly.
You can see this in the files I attached. But the real problem starts here. After the straight line path ends, it does not follow the circular path but goes out of the path. Likewise, when I set the guidance_index variable to 2, it follows the circle path correctly, but this time it does not continue with the straight line path.
How can i fix it ?
Thanks a lot.
Best Regards Hi everyone ,
I’m trying to implement a path following algorithm for UAV (Carrot Chase) with matlab for a line-circle path.
I have already implemented the algorithm for straight line and the loiter separately and this codes are work fine. But, since they are geometrically different shapes, they have different algorithms. So we need to switch algorithms when switching between these two shapes if we want to follow this two shapes together . And i added a algorithm for that but i think it’s not working
i have a variable for that named as " guidance index". You can see this variable at the begginning of the code. When i enter this variable 1 the UAV will follow the straight line path firstly. But if i enter this variable 2, the UAV will follow the circle firstly.
You can see this in the files I attached. But the real problem starts here. After the straight line path ends, it does not follow the circular path but goes out of the path. Likewise, when I set the guidance_index variable to 2, it follows the circle path correctly, but this time it does not continue with the straight line path.
How can i fix it ?
Thanks a lot.
Best Regards matlab, path following, uav MATLAB Answers — New Questions
Setting unknown constants in equation for known data
I have data of points and equation with 3 unknown constants.I want to finds the constants that will give me the values of the data how can i do that ?I have data of points and equation with 3 unknown constants.I want to finds the constants that will give me the values of the data how can i do that ? I have data of points and equation with 3 unknown constants.I want to finds the constants that will give me the values of the data how can i do that ? adjust, equation, constants MATLAB Answers — New Questions
I am having trouble understanding this error “To assign to or create a variable in a table, the number of rows must match the height of the table.”, can someone explain?
As stated in the title, I’m struggling with getting rid of error message "To assign to or create a variable in a table, the number of rows must match the height of the table."
Here is a snippit of my original code. The line specifically causing hte probled is the line within the For loop. Sorry if this is a simple question, I do not usually work MATLAB and got thrown into this project. Thank you!
units_tbl(1,:)
values_tbl_new = vertcat(units_tbl(1,:),values_tbl);
for k = 1:length(vars_wanted)
values_tbl_new.(vars_wanted(k)) = values_tbl.(vars_wanted(k));
endAs stated in the title, I’m struggling with getting rid of error message "To assign to or create a variable in a table, the number of rows must match the height of the table."
Here is a snippit of my original code. The line specifically causing hte probled is the line within the For loop. Sorry if this is a simple question, I do not usually work MATLAB and got thrown into this project. Thank you!
units_tbl(1,:)
values_tbl_new = vertcat(units_tbl(1,:),values_tbl);
for k = 1:length(vars_wanted)
values_tbl_new.(vars_wanted(k)) = values_tbl.(vars_wanted(k));
end As stated in the title, I’m struggling with getting rid of error message "To assign to or create a variable in a table, the number of rows must match the height of the table."
Here is a snippit of my original code. The line specifically causing hte probled is the line within the For loop. Sorry if this is a simple question, I do not usually work MATLAB and got thrown into this project. Thank you!
units_tbl(1,:)
values_tbl_new = vertcat(units_tbl(1,:),values_tbl);
for k = 1:length(vars_wanted)
values_tbl_new.(vars_wanted(k)) = values_tbl.(vars_wanted(k));
end matlab MATLAB Answers — New Questions
Save in an array lines after the appearance of a text pattern
Dear all
I was wondering which could be a good method to store in an array the first two columns of the first two lines after the line "Cell (Angstrom):" in the attached file.Dear all
I was wondering which could be a good method to store in an array the first two columns of the first two lines after the line "Cell (Angstrom):" in the attached file. Dear all
I was wondering which could be a good method to store in an array the first two columns of the first two lines after the line "Cell (Angstrom):" in the attached file. text pattern MATLAB Answers — New Questions
how to give input automatically
i have found accuracy and error from nerual network,i have trained the data,i have to give input one by one for several combination as 1,2..1,3..1,4…..1,100..to find accuracy and error..i sholud not give input my myself,it should be done automatically.in train data i have values from of combination 1,2..2,3..1,4…………1,100
i need all datas to be dispalyed with accuracy and errori have found accuracy and error from nerual network,i have trained the data,i have to give input one by one for several combination as 1,2..1,3..1,4…..1,100..to find accuracy and error..i sholud not give input my myself,it should be done automatically.in train data i have values from of combination 1,2..2,3..1,4…………1,100
i need all datas to be dispalyed with accuracy and error i have found accuracy and error from nerual network,i have trained the data,i have to give input one by one for several combination as 1,2..1,3..1,4…..1,100..to find accuracy and error..i sholud not give input my myself,it should be done automatically.in train data i have values from of combination 1,2..2,3..1,4…………1,100
i need all datas to be dispalyed with accuracy and error datamining MATLAB Answers — New Questions
How to remove gaps in timeseries plot to have a continuous graph
Hello Everyone,
I have a timeseries data from a vehicle having gaps in it. FOr example, when the vehicle was running, there is data, but no data is available when the vehicle is turned off. When i plot now, the missig data is filled witha line connecting last measured data to the next measured data (see figure). How can i remove that line and instead have a continuous line.
I highly appreciate for any efforts.Hello Everyone,
I have a timeseries data from a vehicle having gaps in it. FOr example, when the vehicle was running, there is data, but no data is available when the vehicle is turned off. When i plot now, the missig data is filled witha line connecting last measured data to the next measured data (see figure). How can i remove that line and instead have a continuous line.
I highly appreciate for any efforts. Hello Everyone,
I have a timeseries data from a vehicle having gaps in it. FOr example, when the vehicle was running, there is data, but no data is available when the vehicle is turned off. When i plot now, the missig data is filled witha line connecting last measured data to the next measured data (see figure). How can i remove that line and instead have a continuous line.
I highly appreciate for any efforts. timeseries, data handling, matlab plots MATLAB Answers — New Questions
Plot values on a x-y plane from excel – with colorbar
I would like to plot a x-y values from the excel attached on a plane.
I need a colorbar and Latex font.
Thanks everyone!I would like to plot a x-y values from the excel attached on a plane.
I need a colorbar and Latex font.
Thanks everyone! I would like to plot a x-y values from the excel attached on a plane.
I need a colorbar and Latex font.
Thanks everyone! plot, plotting, excel MATLAB Answers — New Questions
How to Calculate Higher-Order Derivatives
There exists a fifth-order implicit function (curve) such that f(x,y)=a (a is a constant)
For example, x^5+x^4*y^1+x^3*y^2+x^2*y^3+x^1*y^4+y^5=10
There exists a 3-dimensional surface such that g(x,y)=z.
For example, z=x^5+xy+y^5
Next, find the cubic curve g(x,y)=z along f(x,y)=a
Then, on the curve z, we want to find (x,y) where dz/dx=0 and dz/dy=0.There exists a fifth-order implicit function (curve) such that f(x,y)=a (a is a constant)
For example, x^5+x^4*y^1+x^3*y^2+x^2*y^3+x^1*y^4+y^5=10
There exists a 3-dimensional surface such that g(x,y)=z.
For example, z=x^5+xy+y^5
Next, find the cubic curve g(x,y)=z along f(x,y)=a
Then, on the curve z, we want to find (x,y) where dz/dx=0 and dz/dy=0. There exists a fifth-order implicit function (curve) such that f(x,y)=a (a is a constant)
For example, x^5+x^4*y^1+x^3*y^2+x^2*y^3+x^1*y^4+y^5=10
There exists a 3-dimensional surface such that g(x,y)=z.
For example, z=x^5+xy+y^5
Next, find the cubic curve g(x,y)=z along f(x,y)=a
Then, on the curve z, we want to find (x,y) where dz/dx=0 and dz/dy=0. implicit function, 3d surface, 2d curve, diff MATLAB Answers — New Questions
Entering Non-Linear System of Equations
Hi All. I am fairly new to Matlab and still learning. I am wondering if one may explain to me how I should enter a system of non-linear equations. For instance the equations I have are: 4*x(1)-x(2)+x(3)-x(1)*x(4) = 0; -x(1)+3*x(2)-2*x(3)-x(2)*x(4) = 0; and x(1)^2+x(2)^2+x(3)^2-1 = 0. Basically I want to enter the equations and use the Newton Method to solve using the Jacobian Matrix. This is how I enetered them in Matlab:
clear all
clc
syms x
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
f2 = -x(1)+3*x(2)-2*x(3)-x(2)*x(4);
f3 = x(1)^2+x(2)^2+x(3)^2-1;
F = [f1;f2;f3];
If I tell the program to run at this point, this is the error I happen to get:
??? Error using ==> mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Error in ==> sym.sym>sym.subsref at 1366
B = mupadmex(‘mllib::subsref’,A.s,inds{:});
Error in ==> NewtonMethosNonLinear at 5
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
I would appreciate some explanation on this since I don’t know how to move next. Thank you.Hi All. I am fairly new to Matlab and still learning. I am wondering if one may explain to me how I should enter a system of non-linear equations. For instance the equations I have are: 4*x(1)-x(2)+x(3)-x(1)*x(4) = 0; -x(1)+3*x(2)-2*x(3)-x(2)*x(4) = 0; and x(1)^2+x(2)^2+x(3)^2-1 = 0. Basically I want to enter the equations and use the Newton Method to solve using the Jacobian Matrix. This is how I enetered them in Matlab:
clear all
clc
syms x
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
f2 = -x(1)+3*x(2)-2*x(3)-x(2)*x(4);
f3 = x(1)^2+x(2)^2+x(3)^2-1;
F = [f1;f2;f3];
If I tell the program to run at this point, this is the error I happen to get:
??? Error using ==> mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Error in ==> sym.sym>sym.subsref at 1366
B = mupadmex(‘mllib::subsref’,A.s,inds{:});
Error in ==> NewtonMethosNonLinear at 5
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
I would appreciate some explanation on this since I don’t know how to move next. Thank you. Hi All. I am fairly new to Matlab and still learning. I am wondering if one may explain to me how I should enter a system of non-linear equations. For instance the equations I have are: 4*x(1)-x(2)+x(3)-x(1)*x(4) = 0; -x(1)+3*x(2)-2*x(3)-x(2)*x(4) = 0; and x(1)^2+x(2)^2+x(3)^2-1 = 0. Basically I want to enter the equations and use the Newton Method to solve using the Jacobian Matrix. This is how I enetered them in Matlab:
clear all
clc
syms x
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
f2 = -x(1)+3*x(2)-2*x(3)-x(2)*x(4);
f3 = x(1)^2+x(2)^2+x(3)^2-1;
F = [f1;f2;f3];
If I tell the program to run at this point, this is the error I happen to get:
??? Error using ==> mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Error in ==> sym.sym>sym.subsref at 1366
B = mupadmex(‘mllib::subsref’,A.s,inds{:});
Error in ==> NewtonMethosNonLinear at 5
f1 = 4*x(1)-x(2)+x(3)-x(1)*x(4);
I would appreciate some explanation on this since I don’t know how to move next. Thank you. jacob shila MATLAB Answers — New Questions
Is it possible to change some parameters during a RL training?
Hello everyone,
For those who don’t know, I am currently working on a supervised learning/RL learning training session with a 3DOF model of a jet aircraft.
My idea is to change, during a training, some parameters such as the number of allowed interventions of the external controller as well as their duration. Another whish is to change accordingly these parametes as the agent makes progress, e.g. its episode reward will increase during training. Is it possible to do this during a training? That is, is it possible to implement some for loops that exploits the trainStats object while the training is runnig? Thank youHello everyone,
For those who don’t know, I am currently working on a supervised learning/RL learning training session with a 3DOF model of a jet aircraft.
My idea is to change, during a training, some parameters such as the number of allowed interventions of the external controller as well as their duration. Another whish is to change accordingly these parametes as the agent makes progress, e.g. its episode reward will increase during training. Is it possible to do this during a training? That is, is it possible to implement some for loops that exploits the trainStats object while the training is runnig? Thank you Hello everyone,
For those who don’t know, I am currently working on a supervised learning/RL learning training session with a 3DOF model of a jet aircraft.
My idea is to change, during a training, some parameters such as the number of allowed interventions of the external controller as well as their duration. Another whish is to change accordingly these parametes as the agent makes progress, e.g. its episode reward will increase during training. Is it possible to do this during a training? That is, is it possible to implement some for loops that exploits the trainStats object while the training is runnig? Thank you reinforcement learning, supervised learning, machine learning, rl, rl block, trainstats, matlab, simulink MATLAB Answers — New Questions
The input format when setting the prismatic joint input options to motion/provided by input
"I understand that when the prismatic joint input is set to motion/provided by input, the position, velocity, and acceleration values are required. However, I am unsure of the exact usage examples in this case. Could someone please provide some clarification?""I understand that when the prismatic joint input is set to motion/provided by input, the position, velocity, and acceleration values are required. However, I am unsure of the exact usage examples in this case. Could someone please provide some clarification?" "I understand that when the prismatic joint input is set to motion/provided by input, the position, velocity, and acceleration values are required. However, I am unsure of the exact usage examples in this case. Could someone please provide some clarification?" simulink, simscape MATLAB Answers — New Questions