`changeFilePaths` function can't change local path - matlab

I want to use mat file in another machine (mac to linux) and try to use changeFilePaths. According the online doc enter link description here
My code is as follows, gTruth.DataSource value doesn't change before and after changeFilePath, why?
matlab version 2022a update 3 is used.
>> load('groundTruthLidar.mat');
Warning: The data source for the following source names could not be loaded. C:\Source
> In groundTruthLidar.loadobj (line 635)
>> gTruth.DataSource
ans =
PointCloudSequenceSource with properties:
Name: "Point Cloud Sequence"
Description: "A PointCloud sequence reader"
SourceName: "C:\Source"
SourceParams: [1×1 struct]
SignalName: "Source"
SignalType: PointCloud
Timestamp: {[0 sec]}
NumSignals: 1
>> currentPathDataSource = "C:\Source";
>> newPathDataSource = fullfile(matlabroot, 'toolbox', 'lidar', 'lidardata');
>> alternativeFilePaths = {[currentPathDataSource newPathDataSource]};
>> unresolvedPaths = changeFilePaths(gTruth, alternativeFilePaths)
unresolvedPaths =
0×0 empty string array
>> gTruth.DataSource
ans =
PointCloudSequenceSource with properties:
Name: "Point Cloud Sequence"
Description: "A PointCloud sequence reader"
SourceName: "C:\Source"
SourceParams: [1×1 struct]
SignalName: "Source"
SignalType: PointCloud
Timestamp: {[0 sec]}
NumSignals: 1
‘alternativeFilePaths’
>> alternativeFilePaths
alternativeFilePaths =
1×2 string array
"C:\Source" "/Applications/MATLAB_R2022a.app/too…"
>> dir(alternativeFilePaths(2))
. lidarLabeler
.. lidardata_VoxelLabels.mat
Contents.m pretrainedPointPillarsDetector.mat
PandasetLidarData.pcd sampleWPILabels.mat
fullParkingLotData.mat scene_data.mat
hesaiFileReaderConfiguration scene_target_reflectances.mat
highwayScene.pcd segmatchMapFullParkingLot.mat
las velodyneSensorBeamAngles.mat
lcc

Related

possible fix of " enclose the batched tensor in a with pyro.plate(...): context "

In this example, the guide step is defined as follows
def guide(params):
# returns the Bernoulli probablility
alpha = pyro.param(
"alpha", torch.tensor(params[0]), constraint=constraints.positive
)
beta = pyro.param(
"beta", torch.tensor(params[1]), constraint=constraints.positive
)
return pyro.sample("beta_dist", dist.Beta(alpha, beta))
svi = pyro.infer.SVI(
model=conditioned_data_model,
guide=guide,
optim=pyro.optim.SGD({"lr": 0.001, "momentum": 0.8}),
loss=pyro.infer.Trace_ELBO(),
)
params_prior = [prior.concentration1, prior.concentration0]
# Iterate over all the data and store results
losses, alpha, beta = [], [], []
pyro.clear_param_store()
num_steps = 3000
for t in range(num_steps):
losses.append(svi.step(params_prior))
alpha.append(pyro.param("alpha").item())
beta.append(pyro.param("beta").item())
posterior_vi = dist.Beta(alpha[-1], beta[-1])
However, running the above step gives the following error, what does those hints of fix mean and how to fix it accordingly?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [9], in <cell line: 15>()
14 num_steps = 3000
15 for t in range(num_steps):
---> 16 losses.append(svi.step(params_prior))
17 alpha.append(pyro.param("alpha").item())
18 beta.append(pyro.param("beta").item())
ValueError: at site "data_dist", invalid log_prob shape
Expected [], actual [100, 1]
Try one of the following fixes:
- enclose the batched tensor in a with pyro.plate(...): context
- .to_event(...) the distribution being sampled
- .permute() data dimensions

create filedatastore of mat files filtering files by filename pattern in matlab

Is it possible to create a filedatastore of mat files filtering files by filename pattern?
So far I got this:
fds = fileDatastore(dir_save,'ReadFcn',#load,'FileExtensions','.mat','IncludeSubfolders',true);
f=1;
while hasdata(fds)
disp(num2str(progress(fds)*100)
dataarray = read(fds);
if ~isempty(strfind(fds.Files{f},myPattern))
%% do somthing
end
f=f+1;
end
But some mat files I will not be using are really large and therefore slow down the process.
I cannot move all the files to 1 directory because my directory structure is like:
d01/file1.mat
d01/myPatternFile.mat
d01/othefile.mat
d02/file1.mat
d02/myPatternFile.mat
d02/othefile.mat
etc
You can use wildcards in the call to fullfile.
Using an example from the documentation of fileDatastore:
% No filtering
>> fds = fileDatastore(fullfile(matlabroot,'toolbox','matlab','demos'),'ReadFcn',#load,'FileExtensions','.mat')
fds =
FileDatastore with properties:
Files: {
'E:\MATLAB64\R2018b\toolbox\matlab\demos\accidents.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\airfoil.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\airlineResults.mat'
... and 37 more
}
UniformRead: 0
ReadFcn: #load
AlternateFileSystemRoots: {}
% Filtering for .mat files starting with "w"
>> fds =
fileDatastore(fullfile(matlabroot,'toolbox','matlab','demos','w*'),'ReadFcn',#load,'FileExtensions','.mat')
fds =
FileDatastore with properties:
Files: {
'E:\MATLAB64\R2018b\toolbox\matlab\demos\west0479.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\wind.mat'
}
UniformRead: 0
ReadFcn: #load
AlternateFileSystemRoots: {}
For checking over different folders, use two wildcards:
>> !mkdir d01
>> !mkdir d02
>> !touch d01/file1.mat
>> !touch d01/myPatternFile.mat
>> !touch d02/file2.mat
>> !touch d02/myPatternFile.mat
>> fileDatastore(fullfile(pwd,'d*\myPattern*'),'ReadFcn',#load,'FileExtensions','.mat')
ans =
FileDatastore with properties:
Files: {
'H:\Documents\56133896\d01\myPatternFile.mat';
'H:\Documents\56133896\d02\myPatternFile.mat'
}
UniformRead: 0
ReadFcn: #load
AlternateFileSystemRoots: {}

Error reading AVI files in MATLAB

I am working on extracting features from avi files using MATLAB. Every time I run the code I get an error "Exception in Reading". Code is:
cd('D:\Classified\negative-videos');
neg_files = dir('*.avi');
% compute negative files
for fileIter=1:size(neg_files,1)
tic;
movie_name = neg_files(fileIter).name;
try
[color_score__,edge_score__,spatio_score__,score__] = lg_model(movie_name,fps,3);
if(score__ < threshold)
true_neg = true_neg + 1 ;
end
if(score__ >= threshold)
false_pos = false_pos + 1 ;
end
fprintf('[ %d / %d ]\tFile : %s\tscore : %f\tcolor_score : %f\tspatio_score : %f\n', fileIter,size(neg_files,1),movie_name, score__,color_score__, spatio_score__);
catch ME1
fprintf('[ %d / %d ]\tFile : %s\t EXCEPTION IN READING \n', fileIter,size(neg_files,1),movie_name);
end
toc;
end
fprintf('INTERMEDIATE\ttrue pos = %d \n false pos = %d \n true neg = %d \n false neg = %d \n', true_pos,false_pos,true_neg, false_neg);
What is the problem with the above code snippet?
The stack trace is as follows:
For each of the 18 videos in my directory I get following error:
[ 1 / 18 ] File : 38-Meter High Dive Goes Wrong.avi EXCEPTION IN READING
ME1 =
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
ME1 =
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
Undefined function or method 'VideoReader' for input arguments of type 'char'.
3x1 struct array with fields:
file
name
line
MATLAB:UndefinedFunction
Elapsed time is 0.017901 seconds.
Apologies for not posing as a comment, but need a little more rep before I'm allowed to.
I agree with #JimInCO, it looks like you don't have VideoReader. It was first introduced in R2010b. You can try using aviread instead if you have an older version.

Shell variable name queried from Matlab has additional character

I'm working with the following script, run_test:
#!/bin/sh
temp=$1;
cat <<EOF | matlab
[status name] = unix('echo $temp');
disp(name);
% some Matlab code
test_complete = 1;
save(name)
exit
EOF
I want to pass a name to the script, run some code then save a .mat file with the name that was passed. However, there is a curious piece of behavior:
[energon2] ~ $ ./run_test 'run1'
Warning: No display specified. You will not be able to display graphics on the screen.
< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> >> >> run1
>> >> >> >> >>
[energon2] ~ $ ls *.mat
run1?.mat
There is a "?" at the end of the file name when it's saved, but not when displayed on command line. This is acceptable for my needs, but a bit irritating to not know why it's occurring. Any explanation would be appreciated.
Edits, solution:
Yuk was correct below in the underlying cause and the use of save('$temp'). I'm now using the following script
#!/bin/sh
temp=$1;
cat <<EOF | matlab
% some Matlab code
test_complete = 1;
save('$temp')
exit
EOF
Thanks for the help.
You name variable has end-of-line as the last character. When you run echo run1 in unix this command display run1 and then "hit enter". In your script all the output of echo are saved to the name variable.
You can confirm it with the following:
>> format compact
>> [status, name] = unix('echo run1')
status =
0
name =
run1
>> numel(name)
ans =
5
>> int8(name(end))
ans =
10
>> int8(sprintf('\n'))
ans =
10
Apparently this character can be a part of a file name in unix, but shell displays it as ?.
Can't you do save($temp) instead?
EDIT: See my comments below for correction and more explanation.

How do I capture the output from the "present" function and store it in a string

In Matlab, I have a IDPOLY object which I wish to "present" and store the resulting text in a text file.
eg if a is an IDPOLY object and I do
>> present(a)
I get
Discrete-time IDPOLY model: A(q)y(t) = B(q)u(t) + e(t)
A(q) = 1 - 1.31 q^-1 + 0.2425 q^-2 - 0.431 q^-3 + 0.4987 q^-4
B1(q) = 0.01357 + 0.04006 q^-1 - 0.04489 q^-2 + 0.007757 q^-3
- 0.1761 q^-4 + 0.06396 q^-5 - 0.2874 q^-6 + 0.3835 q^-7
B2(q) = -0.006397
Estimated using ARX with focus on data set iddata_est_shift
Loss function 0.0617185 and FPE 0.061879
Sampling interval: 0.025
Created: 24-Nov-2010 13:05:10
Last modified: 24-Nov-2010 13:06:56
Does anyone know how to capture this text as I'd like to write it to a text file in a log file. There are no returned arguments from present.
You can try using the diary command.
I've found the evalc() command which does exactly what I need.
evalc
Evaluate MATLAB expression with capture
Syntax
T = evalc(S)
[T, X, Y, Z, ...] = evalc(S)
and pass the expression as a string.