Tag Archives: matlab
making import function for files that have different datetime format
Hi,
I am having some difficulties in importing a file that has datetime format. The main problem is that sometimes the file I want to import has millisecond information and sometimes it does not.
Below is the function that I use to import the file.
function T_data = func_import_MCC_v2(filename, dataLines)
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [8, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 4, "Encoding", "UTF-8");
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["num", "timestamp", "ch1", "ch2"];
opts.VariableTypes = ["double", "datetime", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "timestamp", "InputFormat", "MM/dd/yyyy hh:mm:ss.SSS aa");
% Import the data
T_data = readtable(filename, opts);
%%
T_data.timestamp.TimeZone = ‘America/Denver’;
T_data.timestamp.Format = "dd-MMM-uuuu HH:mm:ss";
Sometimes I need to change one of the code lines as follows (in case the data does not have millisecond information)
opts = setvaropts(opts, "VarName2", "InputFormat", "MM/dd/yyyy hh:mm:ss aa");
Is there any way that I can use a single function that is compatible with the cases (whether it has millisecond information or not)?Hi,
I am having some difficulties in importing a file that has datetime format. The main problem is that sometimes the file I want to import has millisecond information and sometimes it does not.
Below is the function that I use to import the file.
function T_data = func_import_MCC_v2(filename, dataLines)
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [8, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 4, "Encoding", "UTF-8");
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["num", "timestamp", "ch1", "ch2"];
opts.VariableTypes = ["double", "datetime", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "timestamp", "InputFormat", "MM/dd/yyyy hh:mm:ss.SSS aa");
% Import the data
T_data = readtable(filename, opts);
%%
T_data.timestamp.TimeZone = ‘America/Denver’;
T_data.timestamp.Format = "dd-MMM-uuuu HH:mm:ss";
Sometimes I need to change one of the code lines as follows (in case the data does not have millisecond information)
opts = setvaropts(opts, "VarName2", "InputFormat", "MM/dd/yyyy hh:mm:ss aa");
Is there any way that I can use a single function that is compatible with the cases (whether it has millisecond information or not)? Hi,
I am having some difficulties in importing a file that has datetime format. The main problem is that sometimes the file I want to import has millisecond information and sometimes it does not.
Below is the function that I use to import the file.
function T_data = func_import_MCC_v2(filename, dataLines)
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [8, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 4, "Encoding", "UTF-8");
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["num", "timestamp", "ch1", "ch2"];
opts.VariableTypes = ["double", "datetime", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "timestamp", "InputFormat", "MM/dd/yyyy hh:mm:ss.SSS aa");
% Import the data
T_data = readtable(filename, opts);
%%
T_data.timestamp.TimeZone = ‘America/Denver’;
T_data.timestamp.Format = "dd-MMM-uuuu HH:mm:ss";
Sometimes I need to change one of the code lines as follows (in case the data does not have millisecond information)
opts = setvaropts(opts, "VarName2", "InputFormat", "MM/dd/yyyy hh:mm:ss aa");
Is there any way that I can use a single function that is compatible with the cases (whether it has millisecond information or not)? datetime, import, function, multiple MATLAB Answers — New Questions
Why am I unable to access secrets from a web app with MATLAB Web App Server R2024a?
I developed a MATLAB app that fetches data from a database using the secrets functionality. This works successfully in my local machine. However, running the same app as a web app throws the following errors when trying to access the secret:
2024-09-15 15:26:44 webappSendGetSecretCommand :failure: User is not authorized to access this data
2024-09-15 15:26:44 Error using getSecret (line 10)
2024-09-15 15:26:44 No secret value found for secret name ‘mySecret’ in the vault.
I have followed the documentation to set up my MATLAB Web App Server with all of the secrets from my local MATLAB session. I have also enabled SSL and authentication (OIDC) on my Web App Server.
Why am I unable to access secrets through my web app?I developed a MATLAB app that fetches data from a database using the secrets functionality. This works successfully in my local machine. However, running the same app as a web app throws the following errors when trying to access the secret:
2024-09-15 15:26:44 webappSendGetSecretCommand :failure: User is not authorized to access this data
2024-09-15 15:26:44 Error using getSecret (line 10)
2024-09-15 15:26:44 No secret value found for secret name ‘mySecret’ in the vault.
I have followed the documentation to set up my MATLAB Web App Server with all of the secrets from my local MATLAB session. I have also enabled SSL and authentication (OIDC) on my Web App Server.
Why am I unable to access secrets through my web app? I developed a MATLAB app that fetches data from a database using the secrets functionality. This works successfully in my local machine. However, running the same app as a web app throws the following errors when trying to access the secret:
2024-09-15 15:26:44 webappSendGetSecretCommand :failure: User is not authorized to access this data
2024-09-15 15:26:44 Error using getSecret (line 10)
2024-09-15 15:26:44 No secret value found for secret name ‘mySecret’ in the vault.
I have followed the documentation to set up my MATLAB Web App Server with all of the secrets from my local MATLAB session. I have also enabled SSL and authentication (OIDC) on my Web App Server.
Why am I unable to access secrets through my web app? secrets, web, app MATLAB Answers — New Questions
Too many input arguments – idgrey
Hello everyone,
I’m trying to define a grey box model for parameters identification
pars = {ms; mu; meq; ceq; ks; ku; cu; km; cm};
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
but I’m getting this error when running the model:
Error using idgrey (line 367)
The ODE function "QC_rot_func" could not be evaluated successfully using the given set of parameters, sample time
and optional arguments. The error message generated during the evaluation was:
Too many input arguments.
Error in main (line 175)
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
The function ‘QC_rot_func’ is the following:
function [A,B,C,D] = QC_rot_func(pars,Ts)
ms = pars(1);
mu = pars(2);
meq = pars(3);
ceq = pars(4);
ks = pars(5);
ku = pars(6);
cu = pars(7);
km = pars(8);
cm = pars(9);
A = [0 0 0 1 -1 0;
0 0 0 0 1 -1;
0 0 0 0 0 1;
(-ks/ms-km/ms) -ks/ms 0 -cm/ms cm/ms 0;
(ks/mu+km/mu+km/meq) ks/mu -ku/mu (cm/mu+cm/meq) (-cm/mu-cm/meq-ceq/meq) (-cu/mu+ceq/meq);
(ks/mu+km/mu) ks/mu -ku/mu cm/mu -cm/mu -cu/mu];
Bd = [0; 0; -1; 0; cu/mu; cu/mu];
Bdlt = [0; 0; 0; 1/ms; 0; 0];
Bu = [0; 0; 0; 0; 1/meq; 0];
B = [Bd Bdlt Bu];
C = [A(4,:); A(6,:); A(1,:)+A(2,:)];
D = [B(4,:); B(6,:); B(1,:)+B(2,:)];
end
What is the problem in this code? If I try to run the function with parameters as input, I get di A B C D matrices as expected.
Thank you.Hello everyone,
I’m trying to define a grey box model for parameters identification
pars = {ms; mu; meq; ceq; ks; ku; cu; km; cm};
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
but I’m getting this error when running the model:
Error using idgrey (line 367)
The ODE function "QC_rot_func" could not be evaluated successfully using the given set of parameters, sample time
and optional arguments. The error message generated during the evaluation was:
Too many input arguments.
Error in main (line 175)
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
The function ‘QC_rot_func’ is the following:
function [A,B,C,D] = QC_rot_func(pars,Ts)
ms = pars(1);
mu = pars(2);
meq = pars(3);
ceq = pars(4);
ks = pars(5);
ku = pars(6);
cu = pars(7);
km = pars(8);
cm = pars(9);
A = [0 0 0 1 -1 0;
0 0 0 0 1 -1;
0 0 0 0 0 1;
(-ks/ms-km/ms) -ks/ms 0 -cm/ms cm/ms 0;
(ks/mu+km/mu+km/meq) ks/mu -ku/mu (cm/mu+cm/meq) (-cm/mu-cm/meq-ceq/meq) (-cu/mu+ceq/meq);
(ks/mu+km/mu) ks/mu -ku/mu cm/mu -cm/mu -cu/mu];
Bd = [0; 0; -1; 0; cu/mu; cu/mu];
Bdlt = [0; 0; 0; 1/ms; 0; 0];
Bu = [0; 0; 0; 0; 1/meq; 0];
B = [Bd Bdlt Bu];
C = [A(4,:); A(6,:); A(1,:)+A(2,:)];
D = [B(4,:); B(6,:); B(1,:)+B(2,:)];
end
What is the problem in this code? If I try to run the function with parameters as input, I get di A B C D matrices as expected.
Thank you. Hello everyone,
I’m trying to define a grey box model for parameters identification
pars = {ms; mu; meq; ceq; ks; ku; cu; km; cm};
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
but I’m getting this error when running the model:
Error using idgrey (line 367)
The ODE function "QC_rot_func" could not be evaluated successfully using the given set of parameters, sample time
and optional arguments. The error message generated during the evaluation was:
Too many input arguments.
Error in main (line 175)
linear_model = idgrey(‘QC_rot_func’,pars,’c’);
The function ‘QC_rot_func’ is the following:
function [A,B,C,D] = QC_rot_func(pars,Ts)
ms = pars(1);
mu = pars(2);
meq = pars(3);
ceq = pars(4);
ks = pars(5);
ku = pars(6);
cu = pars(7);
km = pars(8);
cm = pars(9);
A = [0 0 0 1 -1 0;
0 0 0 0 1 -1;
0 0 0 0 0 1;
(-ks/ms-km/ms) -ks/ms 0 -cm/ms cm/ms 0;
(ks/mu+km/mu+km/meq) ks/mu -ku/mu (cm/mu+cm/meq) (-cm/mu-cm/meq-ceq/meq) (-cu/mu+ceq/meq);
(ks/mu+km/mu) ks/mu -ku/mu cm/mu -cm/mu -cu/mu];
Bd = [0; 0; -1; 0; cu/mu; cu/mu];
Bdlt = [0; 0; 0; 1/ms; 0; 0];
Bu = [0; 0; 0; 0; 1/meq; 0];
B = [Bd Bdlt Bu];
C = [A(4,:); A(6,:); A(1,:)+A(2,:)];
D = [B(4,:); B(6,:); B(1,:)+B(2,:)];
end
What is the problem in this code? If I try to run the function with parameters as input, I get di A B C D matrices as expected.
Thank you. greybox, odefunction MATLAB Answers — New Questions
Region GRowing image segmentation
I want to use region growing image segmentation technique to segment an image. How can I find and apply region growing image segmentation technique.I want to use region growing image segmentation technique to segment an image. How can I find and apply region growing image segmentation technique. I want to use region growing image segmentation technique to segment an image. How can I find and apply region growing image segmentation technique. region growing MATLAB Answers — New Questions
How to set correct number of arguments in map.rasterref.MapCellsReference ?
I am using following matlab code to create Raster Map
% Create the MapCellsReference object with the correct parameters
R = map.rasterref.MapCellsReference(…
croppedImageSize, xlimits, ylimits, …
‘ColumnsStartFrom’, ‘west’, …
‘RowsStartFrom’, ‘north’);
However, it gives following error
Error using map.rasterref.MapCellsReference (line 254)
Incorrect number of arguments.
please suggest me correct arguments.
kuldeepI am using following matlab code to create Raster Map
% Create the MapCellsReference object with the correct parameters
R = map.rasterref.MapCellsReference(…
croppedImageSize, xlimits, ylimits, …
‘ColumnsStartFrom’, ‘west’, …
‘RowsStartFrom’, ‘north’);
However, it gives following error
Error using map.rasterref.MapCellsReference (line 254)
Incorrect number of arguments.
please suggest me correct arguments.
kuldeep I am using following matlab code to create Raster Map
% Create the MapCellsReference object with the correct parameters
R = map.rasterref.MapCellsReference(…
croppedImageSize, xlimits, ylimits, …
‘ColumnsStartFrom’, ‘west’, …
‘RowsStartFrom’, ‘north’);
However, it gives following error
Error using map.rasterref.MapCellsReference (line 254)
Incorrect number of arguments.
please suggest me correct arguments.
kuldeep how to set correct number of arguments ? MATLAB Answers — New Questions
Can’t understand why Pwelch claims window is larger than input signal
segment_length = 1229;
hannw = hann(segment_length);
overlap_length = round(segment_length / 2);
disp(size(SuperTrialH2Hit))
returns 30 207701
[pxx4HH, hz4HH] = pwelch(SuperTrialH2Hit, hannw, overlap_length, nextpower2(numel(SuperTrialH2Hit)), SR);
returns
Error using signal.internal.spectral.welchparse>segment_info (line 345)
The length of the segments cannot be greater than the length of the input signal.
Error in signal.internal.spectral.welchparse (line 34)
[L,noverlap,win] = segment_info(M,winp,noverlap1);
Error in welch (line 56)
signal.internal.spectral.welchparse(x,esttype,args{:});
Error in pwelch (line 174)
[welchOut{1:nargout}] = welch(x,funcName,inputArgs{:});segment_length = 1229;
hannw = hann(segment_length);
overlap_length = round(segment_length / 2);
disp(size(SuperTrialH2Hit))
returns 30 207701
[pxx4HH, hz4HH] = pwelch(SuperTrialH2Hit, hannw, overlap_length, nextpower2(numel(SuperTrialH2Hit)), SR);
returns
Error using signal.internal.spectral.welchparse>segment_info (line 345)
The length of the segments cannot be greater than the length of the input signal.
Error in signal.internal.spectral.welchparse (line 34)
[L,noverlap,win] = segment_info(M,winp,noverlap1);
Error in welch (line 56)
signal.internal.spectral.welchparse(x,esttype,args{:});
Error in pwelch (line 174)
[welchOut{1:nargout}] = welch(x,funcName,inputArgs{:}); segment_length = 1229;
hannw = hann(segment_length);
overlap_length = round(segment_length / 2);
disp(size(SuperTrialH2Hit))
returns 30 207701
[pxx4HH, hz4HH] = pwelch(SuperTrialH2Hit, hannw, overlap_length, nextpower2(numel(SuperTrialH2Hit)), SR);
returns
Error using signal.internal.spectral.welchparse>segment_info (line 345)
The length of the segments cannot be greater than the length of the input signal.
Error in signal.internal.spectral.welchparse (line 34)
[L,noverlap,win] = segment_info(M,winp,noverlap1);
Error in welch (line 56)
signal.internal.spectral.welchparse(x,esttype,args{:});
Error in pwelch (line 174)
[welchOut{1:nargout}] = welch(x,funcName,inputArgs{:}); pwelch, psd, segement, signal processing MATLAB Answers — New Questions
Matlab crashes when I try to access Gpu
Hi, I am running Matlab 2021a, and have Nvedia GeForce GTX 1660 Ti.
I have installed latest CUDA, both the toolkit and the driver, 12.1. But still my Matlab crashes, whenever I type "gpuDevice" or trainNetwork, or any command which uses gpu.
I have run out of things I can try, does anyone know where the problem might be?Hi, I am running Matlab 2021a, and have Nvedia GeForce GTX 1660 Ti.
I have installed latest CUDA, both the toolkit and the driver, 12.1. But still my Matlab crashes, whenever I type "gpuDevice" or trainNetwork, or any command which uses gpu.
I have run out of things I can try, does anyone know where the problem might be? Hi, I am running Matlab 2021a, and have Nvedia GeForce GTX 1660 Ti.
I have installed latest CUDA, both the toolkit and the driver, 12.1. But still my Matlab crashes, whenever I type "gpuDevice" or trainNetwork, or any command which uses gpu.
I have run out of things I can try, does anyone know where the problem might be? cuda, gpu MATLAB Answers — New Questions
Create (equal density) spaced vector in MATLAB
I would like to create a spaced x-axis vector. linspace() results with the equally spaced vector. However, applying linspace to my data (image shown below) ends up losing a major chunk of information in the high density area. So I would like to produce an unequal spaced vector adjusted based on density. (Do suggest me if you feel there is any other method would work best for my dataset).
Thanks,I would like to create a spaced x-axis vector. linspace() results with the equally spaced vector. However, applying linspace to my data (image shown below) ends up losing a major chunk of information in the high density area. So I would like to produce an unequal spaced vector adjusted based on density. (Do suggest me if you feel there is any other method would work best for my dataset).
Thanks, I would like to create a spaced x-axis vector. linspace() results with the equally spaced vector. However, applying linspace to my data (image shown below) ends up losing a major chunk of information in the high density area. So I would like to produce an unequal spaced vector adjusted based on density. (Do suggest me if you feel there is any other method would work best for my dataset).
Thanks, matlab, vector MATLAB Answers — New Questions
How can I find the power factor when my system contains harmonics?
Hello, How can I find the power factor when my system contains harmonics? Which block should I use to measure P and Q in order to calculate the power factor in the case where harmonics are present in the system? What formula should I use for the calculation?Hello, How can I find the power factor when my system contains harmonics? Which block should I use to measure P and Q in order to calculate the power factor in the case where harmonics are present in the system? What formula should I use for the calculation? Hello, How can I find the power factor when my system contains harmonics? Which block should I use to measure P and Q in order to calculate the power factor in the case where harmonics are present in the system? What formula should I use for the calculation? simulink, harmonic, power factor MATLAB Answers — New Questions
Generating a cosine wave with variable frequency where frequency is an output from a lookup table
I am trying to generate a sine/cosine wave with a variable frequency. Here’s how I did it.
I took a PN sequence generator with samples per frame 3 and converted those three samples in 1 frame to a decimal number by a MATLAB function block and passes it to a lookup table (1-D) as breakup points [0;1;2;3;4;5;6;7] and gave some data [100;200;300;400;500;600;700;800]. This data is given to a MATLAB function block which takes the values of the lookup table and time from clock block and gives me the result cos(2*pi*f*t). Atleast, this is what it looks like. But, when I ran it oscilloscope haven’t shown me any cosine waves rather, it showed me a constant signal of 1 unit.I am trying to generate a sine/cosine wave with a variable frequency. Here’s how I did it.
I took a PN sequence generator with samples per frame 3 and converted those three samples in 1 frame to a decimal number by a MATLAB function block and passes it to a lookup table (1-D) as breakup points [0;1;2;3;4;5;6;7] and gave some data [100;200;300;400;500;600;700;800]. This data is given to a MATLAB function block which takes the values of the lookup table and time from clock block and gives me the result cos(2*pi*f*t). Atleast, this is what it looks like. But, when I ran it oscilloscope haven’t shown me any cosine waves rather, it showed me a constant signal of 1 unit. I am trying to generate a sine/cosine wave with a variable frequency. Here’s how I did it.
I took a PN sequence generator with samples per frame 3 and converted those three samples in 1 frame to a decimal number by a MATLAB function block and passes it to a lookup table (1-D) as breakup points [0;1;2;3;4;5;6;7] and gave some data [100;200;300;400;500;600;700;800]. This data is given to a MATLAB function block which takes the values of the lookup table and time from clock block and gives me the result cos(2*pi*f*t). Atleast, this is what it looks like. But, when I ran it oscilloscope haven’t shown me any cosine waves rather, it showed me a constant signal of 1 unit. communication, matlab function, 5g, spread sprectrum, simulink MATLAB Answers — New Questions
Standalone mcc app cannot import class within python module
I have an app made via mcc. In this app I need to call a python 2.7 class within a python 2.7 module. I am able to insert the path to the module to the python search path via
insert(py.sys.path, int32(0), PythonModulePath)
I am also able to import the module via
py.importlib.import_module(‘module’)
whose return lists all the correct classes and modules.
but when I try to initialize the class py.module.class(‘init args’) The complied class returns:
Unable to resolve the name py.module.class
MATLAB:undefinedVarOrClass
What is going on here? Why is it unable to identify the class?I have an app made via mcc. In this app I need to call a python 2.7 class within a python 2.7 module. I am able to insert the path to the module to the python search path via
insert(py.sys.path, int32(0), PythonModulePath)
I am also able to import the module via
py.importlib.import_module(‘module’)
whose return lists all the correct classes and modules.
but when I try to initialize the class py.module.class(‘init args’) The complied class returns:
Unable to resolve the name py.module.class
MATLAB:undefinedVarOrClass
What is going on here? Why is it unable to identify the class? I have an app made via mcc. In this app I need to call a python 2.7 class within a python 2.7 module. I am able to insert the path to the module to the python search path via
insert(py.sys.path, int32(0), PythonModulePath)
I am also able to import the module via
py.importlib.import_module(‘module’)
whose return lists all the correct classes and modules.
but when I try to initialize the class py.module.class(‘init args’) The complied class returns:
Unable to resolve the name py.module.class
MATLAB:undefinedVarOrClass
What is going on here? Why is it unable to identify the class? python, mcc, matlab compiler, standalone app MATLAB Answers — New Questions
Mapping 1D vector to 2D area
load xPoints; load yPoints; j=boundary(xPoints,yPoints,0.1); Plot(xPoints(j),yPoints(j))
<</matlabcentral/answers/uploaded_files/1780075/IMG-20240927-WA0011.jpg>>
%How do I map the x-values to y-values here?load xPoints; load yPoints; j=boundary(xPoints,yPoints,0.1); Plot(xPoints(j),yPoints(j))
<</matlabcentral/answers/uploaded_files/1780075/IMG-20240927-WA0011.jpg>>
%How do I map the x-values to y-values here? load xPoints; load yPoints; j=boundary(xPoints,yPoints,0.1); Plot(xPoints(j),yPoints(j))
<</matlabcentral/answers/uploaded_files/1780075/IMG-20240927-WA0011.jpg>>
%How do I map the x-values to y-values here? mapping MATLAB Answers — New Questions
J1939 Network COnfig warnings
I know the databases I am using are correct….however, seems like when I try to attach a dbc file to my simulink model, I’ll get a warning that the dbc file MAY NOT be a valid J1939 database……
again, sometimes I get the message and simulink WILL NOT select the database during config……but other times, I CAN SELECT the same database and get no warnings…???????I know the databases I am using are correct….however, seems like when I try to attach a dbc file to my simulink model, I’ll get a warning that the dbc file MAY NOT be a valid J1939 database……
again, sometimes I get the message and simulink WILL NOT select the database during config……but other times, I CAN SELECT the same database and get no warnings…??????? I know the databases I am using are correct….however, seems like when I try to attach a dbc file to my simulink model, I’ll get a warning that the dbc file MAY NOT be a valid J1939 database……
again, sometimes I get the message and simulink WILL NOT select the database during config……but other times, I CAN SELECT the same database and get no warnings…??????? j1939 network cnfig bug? MATLAB Answers — New Questions
Export Timetable data to Excel
I have a lot of rainfall data which has been uploaded to thingspeak. I want to download some of that data and analyse it in Excel. I was hoping to use the MATLab analysis to do this.
Bearing in mind I am fairly new to this and programming isn’t my thing.
I was hoping to use the following code which as far as I understand extracts the data in TimeTable format and then use the writetimetable function to create an Excel spreadsheet. When I run it it extracts the data and displays it as I want without error but I don’t know what happens to the xlsx file.
I’m probably missing something
readChannelID = ******;
readAPIKey = ‘******’;
RainFieldID = 1;
RainFall = thingSpeakRead(readChannelID,’Fields’,RainFieldID,’NumDays’,7,’ReadKey’,readAPIKey,OutputFormat=’TimeTable’);
display(RainFall,’Rainfall’);
writetimetable(RainFall,’TT.xlsx’)I have a lot of rainfall data which has been uploaded to thingspeak. I want to download some of that data and analyse it in Excel. I was hoping to use the MATLab analysis to do this.
Bearing in mind I am fairly new to this and programming isn’t my thing.
I was hoping to use the following code which as far as I understand extracts the data in TimeTable format and then use the writetimetable function to create an Excel spreadsheet. When I run it it extracts the data and displays it as I want without error but I don’t know what happens to the xlsx file.
I’m probably missing something
readChannelID = ******;
readAPIKey = ‘******’;
RainFieldID = 1;
RainFall = thingSpeakRead(readChannelID,’Fields’,RainFieldID,’NumDays’,7,’ReadKey’,readAPIKey,OutputFormat=’TimeTable’);
display(RainFall,’Rainfall’);
writetimetable(RainFall,’TT.xlsx’) I have a lot of rainfall data which has been uploaded to thingspeak. I want to download some of that data and analyse it in Excel. I was hoping to use the MATLab analysis to do this.
Bearing in mind I am fairly new to this and programming isn’t my thing.
I was hoping to use the following code which as far as I understand extracts the data in TimeTable format and then use the writetimetable function to create an Excel spreadsheet. When I run it it extracts the data and displays it as I want without error but I don’t know what happens to the xlsx file.
I’m probably missing something
readChannelID = ******;
readAPIKey = ‘******’;
RainFieldID = 1;
RainFall = thingSpeakRead(readChannelID,’Fields’,RainFieldID,’NumDays’,7,’ReadKey’,readAPIKey,OutputFormat=’TimeTable’);
display(RainFall,’Rainfall’);
writetimetable(RainFall,’TT.xlsx’) timetable, excel MATLAB Answers — New Questions
Matlab crashes when Intel MKL’s function Pardiso is called
Hello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
AnteHello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
Ante Hello everyone!
I am currently working with Matlab R2021b on Ubuntu 22.04. I am writing a program that will solve linear sparse system of equations, and I am trying to solve it with Pardiso function from Intel MKL library.
I have successfully compiled Mex file in C (that is calling Pardiso function); however when I call Mex file, Matlab crashes without any output or message.
I am using GCC to compile my Mex file. This is the code for compilation:
mex CFLAGS="$CFLAGS -m64" LDFLAGS="$LDFLAGS -m64" pardiso_sparse.c -I/opt/intel/oneapi/mkl/2024.2/include -L/opt/intel/oneapi/mkl/2024.2/lib -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
Here is the Mex file itself. It is quite short:
#include "mex.h"
#include "math.h"
#include "matrix.h"
#include "stdint.h"
#include "mkl.h"
/*#define PARDISO_MAX_SIZE 64*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *vals, *RG;
int32_t *rows, *cols;
int32_t n;
// input
vals = mxGetPr(prhs[0]);
rows = (int32_t*) mxGetData(prhs[1]);
cols = (int32_t*) mxGetData(prhs[2]);
RG = mxGetPr(prhs[3]);
n = (int32_t) mxGetScalar(prhs[4]);
// Create the output solution vector x (n x 1)
plhs[0] = mxCreateDoubleMatrix(n, 1, mxREAL);
double *sol = mxGetPr(plhs[0]);
// PARDISO control parameters
void *pt[64] = {0}; // Internal solver memory pointer
MKL_INT iparm[64] ; // Control parameters
MKL_INT maxfct = 1, mnum = 1, phase, error = 0, msglvl = 1;
MKL_INT mtype = 2; // Real symmetric matrix
MKL_INT n_mkl = (MKL_INT)n;
MKL_INT nrhs_mkl = 1; // Number of right-hand sides (for solving Ax=b)
MKL_INT idum; // Dummy integer used for PARDISO
double ddum;
// Initialize PARDISO control parameters to default
iparm[0] = 0; // Use default PARDISO parameters
// Step 1: Reordering and symbolic factorization
printf("Analysis is running!");
phase = 11;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, NULL, NULL, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during symbolic factorization: %d", error);
}
printf("First phase done!");
// Step 2: Numerical factorization
phase = 22;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during numerical factorization: %d", error);
}
printf("Second phase done!");
// Step 3: Solve and iterative refinement
phase = 33;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, vals, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, RG, sol, &error);
if (error != 0) {
mexErrMsgIdAndTxt("MATLAB:mexfile:pardisoError", "Error during solution: %d", error);
}
printf("Thrid phase done!");
// Step 4: Release internal memory
phase = -1;
pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n_mkl, &ddum, (MKL_INT *)rows, (MKL_INT *)cols, &idum, &nrhs_mkl,
iparm, &msglvl, &ddum, &ddum, &error);
}
Can anyone give me a solution to this? I’ve been trying to run this code for more than a week!
Ante matlab, intel mkl, sparse, mex compiler, ubuntu MATLAB Answers — New Questions
how to do edit table type data and do sliding window in matlab
I have imported excel file into matlab and stored it as type of table, the file contains customers’ name, number, date of purchase and other such kind of things. now what I to do is to achieve following function in matlab: 1. I can filter specific customer’s record by entering his name 2. the showed records of this specific customer are sliding windows, every unit of the sliding windows is like from day1 to day 10 and next is from day5 to day15. so can anyone help me out ? the only hint I know is to use cell type, but I still don’t know what is the code look likeI have imported excel file into matlab and stored it as type of table, the file contains customers’ name, number, date of purchase and other such kind of things. now what I to do is to achieve following function in matlab: 1. I can filter specific customer’s record by entering his name 2. the showed records of this specific customer are sliding windows, every unit of the sliding windows is like from day1 to day 10 and next is from day5 to day15. so can anyone help me out ? the only hint I know is to use cell type, but I still don’t know what is the code look like I have imported excel file into matlab and stored it as type of table, the file contains customers’ name, number, date of purchase and other such kind of things. now what I to do is to achieve following function in matlab: 1. I can filter specific customer’s record by entering his name 2. the showed records of this specific customer are sliding windows, every unit of the sliding windows is like from day1 to day 10 and next is from day5 to day15. so can anyone help me out ? the only hint I know is to use cell type, but I still don’t know what is the code look like sliding window, cell array, matlab, importing excel data, find function MATLAB Answers — New Questions
Motion of a square
Good morning, I am asking for a review of the code that I am leaving as an attachment. The objective of the code should be to take as input the position of 4 points inside the square (integral with respect to the square, fixed in the face). Through an analysis of the variation of the 4 x and y coordinates you want to construct a code that simulates the motion of the square built around these points. What is to appear on the screen will be a black square with 4 fixed white points inside moving in a gray plane. The data with the positions are extracted from a text file that comes from a camera capture. Thank you in advance for your help.Good morning, I am asking for a review of the code that I am leaving as an attachment. The objective of the code should be to take as input the position of 4 points inside the square (integral with respect to the square, fixed in the face). Through an analysis of the variation of the 4 x and y coordinates you want to construct a code that simulates the motion of the square built around these points. What is to appear on the screen will be a black square with 4 fixed white points inside moving in a gray plane. The data with the positions are extracted from a text file that comes from a camera capture. Thank you in advance for your help. Good morning, I am asking for a review of the code that I am leaving as an attachment. The objective of the code should be to take as input the position of 4 points inside the square (integral with respect to the square, fixed in the face). Through an analysis of the variation of the 4 x and y coordinates you want to construct a code that simulates the motion of the square built around these points. What is to appear on the screen will be a black square with 4 fixed white points inside moving in a gray plane. The data with the positions are extracted from a text file that comes from a camera capture. Thank you in advance for your help. motion simulation MATLAB Answers — New Questions
How to get the error in two different curve ?
I have two data set , A1 and B1 are 151 datas ,and A2 and B2 are 98 datas(as the attached file Data.mat).
The image below are the two curves.
<</matlabcentral/answers/uploaded_files/129768/2.jpg>>
<</matlabcentral/answers/uploaded_files/129769/1.jpg>>
Because of the different number of these two data,I can’t subtract each value directly.
Then,How do I get the error between them ?
———————-The following steps are what I did.———————–
1. Using function ‘saveas’ to save these two image.Before saving these image, I had adjusted the X axis and Y axis in these two image to the same scale.
2. Using function ‘imread’ and ‘rgb2gray’ to read these two image and turn them into black and white graphics.
3. Using function ‘imsubtract’ to get the error between them.
——————————————————————————————
There are some disadvantage in this way.
So I want to ask the better way to slove this problem.
Thank you so much !I have two data set , A1 and B1 are 151 datas ,and A2 and B2 are 98 datas(as the attached file Data.mat).
The image below are the two curves.
<</matlabcentral/answers/uploaded_files/129768/2.jpg>>
<</matlabcentral/answers/uploaded_files/129769/1.jpg>>
Because of the different number of these two data,I can’t subtract each value directly.
Then,How do I get the error between them ?
———————-The following steps are what I did.———————–
1. Using function ‘saveas’ to save these two image.Before saving these image, I had adjusted the X axis and Y axis in these two image to the same scale.
2. Using function ‘imread’ and ‘rgb2gray’ to read these two image and turn them into black and white graphics.
3. Using function ‘imsubtract’ to get the error between them.
——————————————————————————————
There are some disadvantage in this way.
So I want to ask the better way to slove this problem.
Thank you so much ! I have two data set , A1 and B1 are 151 datas ,and A2 and B2 are 98 datas(as the attached file Data.mat).
The image below are the two curves.
<</matlabcentral/answers/uploaded_files/129768/2.jpg>>
<</matlabcentral/answers/uploaded_files/129769/1.jpg>>
Because of the different number of these two data,I can’t subtract each value directly.
Then,How do I get the error between them ?
———————-The following steps are what I did.———————–
1. Using function ‘saveas’ to save these two image.Before saving these image, I had adjusted the X axis and Y axis in these two image to the same scale.
2. Using function ‘imread’ and ‘rgb2gray’ to read these two image and turn them into black and white graphics.
3. Using function ‘imsubtract’ to get the error between them.
——————————————————————————————
There are some disadvantage in this way.
So I want to ask the better way to slove this problem.
Thank you so much ! error, two curve MATLAB Answers — New Questions
Is there a way to tell the compiler to exclude the JVM if using compiler.build.StandaloneApplicationOptions?
I have an existing build script for a console application that compiles with the following command:
compiler.build.standaloneApplication(opts)
where opts is of the type:
compiler.build.StandaloneApplicationOptions
Is there a way to tell the runtime to exclude the JVM inside the opts argument so that it will load faster? I basically want to do the same thing as:
mcc -m -R -nojvm
Unfortunately, I don’t want to re-write this build script because it is a standard script we use.
Thanks in advance,
DaveI have an existing build script for a console application that compiles with the following command:
compiler.build.standaloneApplication(opts)
where opts is of the type:
compiler.build.StandaloneApplicationOptions
Is there a way to tell the runtime to exclude the JVM inside the opts argument so that it will load faster? I basically want to do the same thing as:
mcc -m -R -nojvm
Unfortunately, I don’t want to re-write this build script because it is a standard script we use.
Thanks in advance,
Dave I have an existing build script for a console application that compiles with the following command:
compiler.build.standaloneApplication(opts)
where opts is of the type:
compiler.build.StandaloneApplicationOptions
Is there a way to tell the runtime to exclude the JVM inside the opts argument so that it will load faster? I basically want to do the same thing as:
mcc -m -R -nojvm
Unfortunately, I don’t want to re-write this build script because it is a standard script we use.
Thanks in advance,
Dave matlab compiler, jvm, build options, standalone application MATLAB Answers — New Questions
Can anybody help me to code boundary conditions in MATLAB for Keller Box Method?
Can anybody help me to code boundary conditions in MATLAB for Keller Box Method?
f^’=1,f=S,θ^’=-r_1 [1+θ],ϕ^’=-r_2 [1+ϕ] at η=0
f^’=0,f^”=0,θ=0,ϕ=0 as η→∞Can anybody help me to code boundary conditions in MATLAB for Keller Box Method?
f^’=1,f=S,θ^’=-r_1 [1+θ],ϕ^’=-r_2 [1+ϕ] at η=0
f^’=0,f^”=0,θ=0,ϕ=0 as η→∞ Can anybody help me to code boundary conditions in MATLAB for Keller Box Method?
f^’=1,f=S,θ^’=-r_1 [1+θ],ϕ^’=-r_2 [1+ϕ] at η=0
f^’=0,f^”=0,θ=0,ϕ=0 as η→∞ keller box method, differential equations MATLAB Answers — New Questions