Category: Matlab
Category Archives: Matlab
How can I package the MATLAB Runtime Installer with my standalone application from a specific directory?
I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications?I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications? I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications? applicationcompiler, matlabruntimeinstaller MATLAB Answers — New Questions
Contourf: fill inside instead of outside
Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v)Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v) Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v) contour, fill MATLAB Answers — New Questions
Simulink outputs variables but they are not being sent to the workspace.
While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019.While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019. While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019. workspace, simulink MATLAB Answers — New Questions
how to write a code on matlab for a function that runs until she gets a regional answer
hi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
endhi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
end hi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
end function, functions, loop, if statement, while loop MATLAB Answers — New Questions
2 synchronized objects in viewer3d
(Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André(Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André (Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André viewer3d, linkaxes, volshow MATLAB Answers — New Questions
How to increase resolution from gshhs?
Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’)Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’) Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’) gshhs, increase reoslution MATLAB Answers — New Questions
Simbiology Previous Initial Parameters
Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know!Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know! Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know! matlab, simbiology, initial parameters, curve fitting, simulation MATLAB Answers — New Questions
Why are functions called by “eval” not found by my compiled standalone application?
I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application?I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application? I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application? eval, compiler MATLAB Answers — New Questions
installing matlab and simulink on pi – ‘verifying sudo user privilege failed’
hi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thankshi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thanks hi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thanks raspberry pi, matlab, simulink, install MATLAB Answers — New Questions
Error message when trying to run System Validation in Fuzzy Logic Designer app
When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine.When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine. When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine. fuzzy logic designer app, system validation MATLAB Answers — New Questions
Reading a text file using readtable, Matlab stubbornly refuses to accept dates in anything but US-format
Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870 Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870 readtable, date format MATLAB Answers — New Questions
GPU Training RL Toolbox on R2022a
Hello everyone,
I am trying to train my agent with using Reinforcement Learning Toolbox Matlab2022a. Unfortunately, I couldn’t run the training due to some packages were updated. rlRepresentationOptions was contain ‘UseDevice’,’gpu’ option, but the package has been changed to rlOptimizerOptions without any ‘UseDevice’ option. How can I run my training with using gpu? Thank you in advance.Hello everyone,
I am trying to train my agent with using Reinforcement Learning Toolbox Matlab2022a. Unfortunately, I couldn’t run the training due to some packages were updated. rlRepresentationOptions was contain ‘UseDevice’,’gpu’ option, but the package has been changed to rlOptimizerOptions without any ‘UseDevice’ option. How can I run my training with using gpu? Thank you in advance. Hello everyone,
I am trying to train my agent with using Reinforcement Learning Toolbox Matlab2022a. Unfortunately, I couldn’t run the training due to some packages were updated. rlRepresentationOptions was contain ‘UseDevice’,’gpu’ option, but the package has been changed to rlOptimizerOptions without any ‘UseDevice’ option. How can I run my training with using gpu? Thank you in advance. reinforcement learning, training, machine learning MATLAB Answers — New Questions
How to loop through cell array and apply script to each double?
Hi,
I have a cell array of cell arrays of doubles called "C_512_numeric". I have the script called edit and I want to loop through all columns in the doubles in C_512_numeric and use the column data as input for edit (first argument). I have attached the script.
How would I write this code?Hi,
I have a cell array of cell arrays of doubles called "C_512_numeric". I have the script called edit and I want to loop through all columns in the doubles in C_512_numeric and use the column data as input for edit (first argument). I have attached the script.
How would I write this code? Hi,
I have a cell array of cell arrays of doubles called "C_512_numeric". I have the script called edit and I want to loop through all columns in the doubles in C_512_numeric and use the column data as input for edit (first argument). I have attached the script.
How would I write this code? cells, doubles, script, input MATLAB Answers — New Questions
how to reduce blob analysis rate in video so that object counting can happen every 3 seconds
I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape)I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape) I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape) computer vision, blob MATLAB Answers — New Questions
How to convert tables into numeric arrays?
Hi I have the data set C_512 (see attached) and I want to make the tables within the cells of the cell array into numeric arrays so that there are no longer any tables in C_512. I used this code below:
% Load the .mat file
load(‘/path/to/C_512.mat’);
% Initialize a new cell array to store numeric arrays
C_512_numeric = cell(size(C_512));
% Loop through each cell and convert its content to numeric arrays
for i = 1:size(C_512, 1)
for j = 1:size(C_512, 2)
T = C_512{i, j};
if istable(T)
C_512_numeric{i, j} = table2array(T);
else
C_512_numeric{i, j} = T; % If it’s already an array or matrix
end
end
end
% Save the numeric data to a new .mat file
save(‘C_512_numeric.mat’, ‘C_512_numeric’);
Unfortunately, C_512_numeric still contains tables. Why is that?Hi I have the data set C_512 (see attached) and I want to make the tables within the cells of the cell array into numeric arrays so that there are no longer any tables in C_512. I used this code below:
% Load the .mat file
load(‘/path/to/C_512.mat’);
% Initialize a new cell array to store numeric arrays
C_512_numeric = cell(size(C_512));
% Loop through each cell and convert its content to numeric arrays
for i = 1:size(C_512, 1)
for j = 1:size(C_512, 2)
T = C_512{i, j};
if istable(T)
C_512_numeric{i, j} = table2array(T);
else
C_512_numeric{i, j} = T; % If it’s already an array or matrix
end
end
end
% Save the numeric data to a new .mat file
save(‘C_512_numeric.mat’, ‘C_512_numeric’);
Unfortunately, C_512_numeric still contains tables. Why is that? Hi I have the data set C_512 (see attached) and I want to make the tables within the cells of the cell array into numeric arrays so that there are no longer any tables in C_512. I used this code below:
% Load the .mat file
load(‘/path/to/C_512.mat’);
% Initialize a new cell array to store numeric arrays
C_512_numeric = cell(size(C_512));
% Loop through each cell and convert its content to numeric arrays
for i = 1:size(C_512, 1)
for j = 1:size(C_512, 2)
T = C_512{i, j};
if istable(T)
C_512_numeric{i, j} = table2array(T);
else
C_512_numeric{i, j} = T; % If it’s already an array or matrix
end
end
end
% Save the numeric data to a new .mat file
save(‘C_512_numeric.mat’, ‘C_512_numeric’);
Unfortunately, C_512_numeric still contains tables. Why is that? convert, tables, numeric array, error, cell MATLAB Answers — New Questions
Simscape version change cause problem
Hi all, we created a simscape model in MATLAB 2021a which perfectly works. When I open it in MATLAB 2024a or in MATLAB online, I receive many errors. One of the error is
"Cannot find library called ‘sm_cable_robot_lib’. "
and
"Pulley-End Alignment1′ cannot be found on MATLAB path or has an invalid path."
I search for sm_cable_robot_lib but no result. Is there any change in simscape in MATLAB 2024?Hi all, we created a simscape model in MATLAB 2021a which perfectly works. When I open it in MATLAB 2024a or in MATLAB online, I receive many errors. One of the error is
"Cannot find library called ‘sm_cable_robot_lib’. "
and
"Pulley-End Alignment1′ cannot be found on MATLAB path or has an invalid path."
I search for sm_cable_robot_lib but no result. Is there any change in simscape in MATLAB 2024? Hi all, we created a simscape model in MATLAB 2021a which perfectly works. When I open it in MATLAB 2024a or in MATLAB online, I receive many errors. One of the error is
"Cannot find library called ‘sm_cable_robot_lib’. "
and
"Pulley-End Alignment1′ cannot be found on MATLAB path or has an invalid path."
I search for sm_cable_robot_lib but no result. Is there any change in simscape in MATLAB 2024? simscape, cable-robot, pulley MATLAB Answers — New Questions
Datetime format capatilization sensitivity inconsistent?
So I was trying to add milliseconds to my datetime variables and found a sort of inconsistency?
When setting datetime format using datetime(‘now’,’Format’,’hh:mm:ss.sss’) , the sss at the end is not capatilization sensitive; but when trying to access and change it using variable_name.Format = ‘hh:mm:ss.SSS’, the SSS at the end is capatilization sensitive.
Is this a minor inconsitency or is this intended? If it’s the latter what is the rationale behind? As it only makes it more confusing imoSo I was trying to add milliseconds to my datetime variables and found a sort of inconsistency?
When setting datetime format using datetime(‘now’,’Format’,’hh:mm:ss.sss’) , the sss at the end is not capatilization sensitive; but when trying to access and change it using variable_name.Format = ‘hh:mm:ss.SSS’, the SSS at the end is capatilization sensitive.
Is this a minor inconsitency or is this intended? If it’s the latter what is the rationale behind? As it only makes it more confusing imo So I was trying to add milliseconds to my datetime variables and found a sort of inconsistency?
When setting datetime format using datetime(‘now’,’Format’,’hh:mm:ss.sss’) , the sss at the end is not capatilization sensitive; but when trying to access and change it using variable_name.Format = ‘hh:mm:ss.SSS’, the SSS at the end is capatilization sensitive.
Is this a minor inconsitency or is this intended? If it’s the latter what is the rationale behind? As it only makes it more confusing imo datetime MATLAB Answers — New Questions
How do you access the datatype of Bus Element Ports in MATLAB
I have a model that outputs a Bus of type ‘TestBus’. The Bus is comprised of three Doubles, which I define and output using ‘Bus Element Outports’.
I would like to access the output datatype of my entire model (which is a ‘TestBus’). However, when I access the datatype of the Bus Element Outports, I receive ‘Double’ instead of ‘TestBus’.
For instance, the following code returns ‘Double’ on my compiled model:
get(<Bus Element Handle>,’CompiledPortDataTypes’).Inport{1}; % Returns Double, should return TestBus
How can I access the Bus output datatype of my Bus Element Ports?I have a model that outputs a Bus of type ‘TestBus’. The Bus is comprised of three Doubles, which I define and output using ‘Bus Element Outports’.
I would like to access the output datatype of my entire model (which is a ‘TestBus’). However, when I access the datatype of the Bus Element Outports, I receive ‘Double’ instead of ‘TestBus’.
For instance, the following code returns ‘Double’ on my compiled model:
get(<Bus Element Handle>,’CompiledPortDataTypes’).Inport{1}; % Returns Double, should return TestBus
How can I access the Bus output datatype of my Bus Element Ports? I have a model that outputs a Bus of type ‘TestBus’. The Bus is comprised of three Doubles, which I define and output using ‘Bus Element Outports’.
I would like to access the output datatype of my entire model (which is a ‘TestBus’). However, when I access the datatype of the Bus Element Outports, I receive ‘Double’ instead of ‘TestBus’.
For instance, the following code returns ‘Double’ on my compiled model:
get(<Bus Element Handle>,’CompiledPortDataTypes’).Inport{1}; % Returns Double, should return TestBus
How can I access the Bus output datatype of my Bus Element Ports? buselement, ports, compiledportdatatypes, outdatatypestr MATLAB Answers — New Questions
How to calculate Coherence Bandwidth from transfer Function H(f)?
Hello,
I have measurement data S21, of many different channels. How can I calculate the coherence Bandwidth of the channels from that?
Thanks a lot for your valuable helpHello,
I have measurement data S21, of many different channels. How can I calculate the coherence Bandwidth of the channels from that?
Thanks a lot for your valuable help Hello,
I have measurement data S21, of many different channels. How can I calculate the coherence Bandwidth of the channels from that?
Thanks a lot for your valuable help communication, digital signal processing MATLAB Answers — New Questions
UIfigure value changes on a while loop
לק"י
Hello!
I have a time series stack of cell masks of 21 timepoints. each mask has a unique gray scale value of its own.
I need to acquire a single pixel grayscale vlaue by clicking on the desired cell mask.
My strategy is to have two figures open at the same time.
The first figure will present the image of a single time sequence and after a pixel will be chosen it’s grayscale value will be saved.
The second figure will present a loop of the time series to allow me for easy identification of the desired cell. I will only see it no interactions made with this loop figure.
This figure is running with a while loop, that will end only when I click and UIfigure (b) of a button, so the condition is when b.Value==0.
When I run the code, I awkwardly get an error when enetring the third while loop.
The code:
filename=’17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’;
info = imfinfo(filename);
numberOfImages = length(info);
j=1;
for i= 1:numberOfImages
crntimg=imread(filename, i);
figure (1)
imshow (crntimg,[]);
impixelinfo
fig = uifigure;
b = uibutton(fig,"state", "Text","Press to end", "IconAlignment","top", …
"Position",[100 100 50 50]);
while b.Value == 0
k=1
crntimgloop=imread(filename, j);
imshow (crntimgloop,[]);
if j<21
j=j+1;
else
j=1;
end
j
end
end
The error output:
j =
3
Invalid or deleted object.
Error in matlab.ui.control.internal.model.AbstractBinaryComponent/get.Value (line 95)
value = obj.PrivateValue;
Error in Cell_mask_identification_over_time (line 13)
while b.Value == 0
I tried to upload the mask’s time series file, but it was too large.
Thanks,
Amit.לק"י
Hello!
I have a time series stack of cell masks of 21 timepoints. each mask has a unique gray scale value of its own.
I need to acquire a single pixel grayscale vlaue by clicking on the desired cell mask.
My strategy is to have two figures open at the same time.
The first figure will present the image of a single time sequence and after a pixel will be chosen it’s grayscale value will be saved.
The second figure will present a loop of the time series to allow me for easy identification of the desired cell. I will only see it no interactions made with this loop figure.
This figure is running with a while loop, that will end only when I click and UIfigure (b) of a button, so the condition is when b.Value==0.
When I run the code, I awkwardly get an error when enetring the third while loop.
The code:
filename=’17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’;
info = imfinfo(filename);
numberOfImages = length(info);
j=1;
for i= 1:numberOfImages
crntimg=imread(filename, i);
figure (1)
imshow (crntimg,[]);
impixelinfo
fig = uifigure;
b = uibutton(fig,"state", "Text","Press to end", "IconAlignment","top", …
"Position",[100 100 50 50]);
while b.Value == 0
k=1
crntimgloop=imread(filename, j);
imshow (crntimgloop,[]);
if j<21
j=j+1;
else
j=1;
end
j
end
end
The error output:
j =
3
Invalid or deleted object.
Error in matlab.ui.control.internal.model.AbstractBinaryComponent/get.Value (line 95)
value = obj.PrivateValue;
Error in Cell_mask_identification_over_time (line 13)
while b.Value == 0
I tried to upload the mask’s time series file, but it was too large.
Thanks,
Amit. לק"י
Hello!
I have a time series stack of cell masks of 21 timepoints. each mask has a unique gray scale value of its own.
I need to acquire a single pixel grayscale vlaue by clicking on the desired cell mask.
My strategy is to have two figures open at the same time.
The first figure will present the image of a single time sequence and after a pixel will be chosen it’s grayscale value will be saved.
The second figure will present a loop of the time series to allow me for easy identification of the desired cell. I will only see it no interactions made with this loop figure.
This figure is running with a while loop, that will end only when I click and UIfigure (b) of a button, so the condition is when b.Value==0.
When I run the code, I awkwardly get an error when enetring the third while loop.
The code:
filename=’17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’;
info = imfinfo(filename);
numberOfImages = length(info);
j=1;
for i= 1:numberOfImages
crntimg=imread(filename, i);
figure (1)
imshow (crntimg,[]);
impixelinfo
fig = uifigure;
b = uibutton(fig,"state", "Text","Press to end", "IconAlignment","top", …
"Position",[100 100 50 50]);
while b.Value == 0
k=1
crntimgloop=imread(filename, j);
imshow (crntimgloop,[]);
if j<21
j=j+1;
else
j=1;
end
j
end
end
The error output:
j =
3
Invalid or deleted object.
Error in matlab.ui.control.internal.model.AbstractBinaryComponent/get.Value (line 95)
value = obj.PrivateValue;
Error in Cell_mask_identification_over_time (line 13)
while b.Value == 0
I tried to upload the mask’s time series file, but it was too large.
Thanks,
Amit. uifigure, loops, while loop MATLAB Answers — New Questions