MATLAB: How I Can Read Matrices From text file and display it at separate Matrices

matricesnotepadreadtext filewrite

I need to read matrices from notepad then display it in two separate matrices .I need also to calculate inverse then write the result back to notepad,please answer as soon as possible I searched for the answer in you tube to understand but I did not find.
THANKS

Best Answer

To read, try csvread(), dlmread(), importdata(), readtable(), textscan(), or a few other ways.
For display, you can use a uitable to display the matrix in a GUI. It's like a grid or spreadsheet control. Here's a demo:
clc;
% Create sample data and row and column headers.
columnHeaders = {'n', 'Data Set #1', 'Data Set #2'};
for n=1:10,
rowHeaders{n} = sprintf('Row #%d', n);
tableData{n,1} = n;
tableData{n,2} = 10*rand(1,1);
tableData{n,3} = sprintf(' Value = %.2f %s %.2f', rand(1,1), 177, rand(1));
end
% Create the table and display it.
hTable = uitable();
% Apply the row and column headers.
set(hTable, 'RowName', rowHeaders);
set(hTable, 'ColumnName', columnHeaders);
% Display the table of values.
set(hTable, 'data', tableData);
% Size the table.
set(hTable, 'units', 'normalized');
set(hTable, 'Position', [.1 .1 .8 .8]);
set(hTable, 'ColumnWidth', {40, 120, 180});
set(gcf,'name','Image Analysis Demo','numbertitle','off')
To write out to a text file, use fullfile(), fopen(), fprintf(), and fclose() - see documentation for examples.
It's nice to see that you looked for a solution on your own (YouTube) before asking here. That's one of the points listed in our tutorial: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer Of course I'd probably search Answers first, then the newsgroup, then YouTube or the internet in general.