Wednesday, October 9, 2024

It's_Magic

 Looking through the Matlab documentation, this morning. ML has its own language,

but is fairly straightforward. It is basically meant to work with matrices and arrays.

Get Started with MATLAB (mathworks.com)


Ended up asking Copilot what was magic about a square matrix.




*     *     *
I use Matlab online, so my files and folders are all in the one Drive. Still, one needs

to undertand about files, folders, and access to these:

Can I create a folder in Matlab?

Yes, you can create a folder in MATLAB using the mkdir function. Here’s a simple example:
% Create a folder named 'newFolder' in the current directory
mkdir('newFolder')
If you want to create a folder within a specific parent directory, you can specify the path:
% Create a folder named 'newFolder' inside 'parentFolder'
mkdir('parentFolder', 'newFolder')
If the parent directory does not exist, MATLAB will attempt to create it as well12.

How do I subsequently access this folder?

You can access the folder you created in MATLAB by changing the current directory to that folder using the cd function. Here’s how you can do it:
% Change the current directory to 'newFolder'
cd('newFolder')
If you created the folder within a specific parent directory, you can specify the full path:
% Change the current directory to 'parentFolder/newFolder'
cd('parentFolder/newFolder')
To verify that you have successfully changed the directory, you can use the pwd function, which returns the current directory:
% Display the current directory
currentDir = pwd
disp(['Current directory: ', currentDir])

How do I list the files in a folder using MATLAB?

You can list the files in a folder using MATLAB with the dir or ls functions. Here’s how you can use each:
Using dir:
The dir function lists the files and folders in the specified directory. If no directory is specified, it lists the contents of the current directory.
% List all files and folders in the current directory
files = dir;
% List all files and folders in a specific directory
files = dir('path_to_directory');
% Display the names of the files and folders
for k = 1:length(files)
    disp(files(k).name)
end
Using ls:
The ls function lists the contents of the current directory or a specified directory.
% List all files and folders in the current directory
ls
% List all files and folders in a specific directory
ls('path_to_directory')
Both functions allow you to use wildcards to match specific patterns. For example, to list all .m files in the current directory:
% Using dir
files = dir('*.m');
% Using ls
ls('*.m')


                                                                           


                                                           *     *     *
Fast-paced walkrough:


Cheat_Sheet:

No comments: