MATLAB Answers

how to open .mat file in matlab?

354 ビュー (過去 30 日間)
Omar B.
Omar B. 2019 年 9 月 16 日
コメント済み: Ahmed 2021 年 1 月 26 日
Hello,
I am tring to open Yeast.mat in matlab , but it does not work.
I got an error (Not enough input arguments.Error in importfile1 (line 9) newData1 =load('NotreDame_yeast.mat', fileToRead1);
function importfile1(fileToRead1)
%IMPORTFILE1(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 16-Sep-2019 02:26:56
% Import the file
newData1 = load('NotreDame_yeast.mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end

  1 件のコメント

Ahmed
Ahmed 2021 年 1 月 26 日
Try to save the mat file in the same directory of your code

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 16 日
You are calling importfile1() without passing in a parameter.
You cannot run importfile1() just by clicking the green Run button: you have to call it from the command line or from some other code.
You need to pass a character vector or a scalar string object. The item you pass can include wildcards, such as 'jan*' to load all variables that begin with "jan"

  3 件のコメント

Omar B.
Omar B. 2019 年 9 月 16 日
How can we call it from the command line? It still does not work.
Walter Roberson
Walter Roberson 2019 年 9 月 16 日
importfile1('jan*')
if you want to import all of the variables that start with 'jan' from the hardcoded mat file (and that file must be in the current directory or else on the MATLAB path)
Omar B.
Omar B. 2019 年 9 月 16 日
Thank you so much.

サインインしてコメントする。

その他の回答 (1 件)

Sebastian Körner
Sebastian Körner 2019 年 9 月 16 日
Not sure what "fileToRead1" is, but per definition it should be the variable you want to load from your file
if you want to load the hole file try:
newData1 = load('NotreDame_yeast.mat');

  2 件のコメント

Sebastian Körner
Sebastian Körner 2019 年 9 月 16 日
you can check the different syntax types of load here:
Omar B.
Omar B. 2019 年 9 月 16 日
Thank you so much.

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by