How to retrieve data from a Excel sheet saved at a particular location in pc?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Hello,
I want to retrieve data from an excel sheet stored at a particular location in the pc, the path of that particular file is provided in the code as below. However, the code is unable to read the file from the given location. I tried the matlab command importdata as well as readmatrix.
sigma_diff=0.5;
beta=0.01;
gamma_nonlin=2*beta;
i=100;
j=1;
speed_F=zeros(i,j);
for j=1:100
mu(i,j)=importdata('D:\Rahul\Data_tokamak\data&plot\data1_non-ctrw\L-mode data from L-mode eqn\data without edge source\Fisher model\data1_L0_sig0.5_f1\a5_term(i,j)');
speed_F(i,j)=sqrt(sigma_diff*data1.variable.turbulence(i,j)*mu(i,j)^2)/(2*gamma_nonlin);
end
Error using importdata
Unable to open file.
Unable to open file.
Accepted Answer
Chunru
on 22 Nov 2023
Moved: Dyuman Joshi
on 22 Nov 2023
You need to provide the extension name (.xlsx ?) to the file.
8 Comments
Dyuman Joshi
on 22 Nov 2023
Also, use readmatrix() over importdata().
Note that readmatrix() will read all the data (in the specified range in a given sheet) at once, you will not need a for loop for that.
ok. Will do that.
But it still not able to read the file. I used the extension .mat as it is a matlab generated file.
rgds
Chunru
on 23 Nov 2023
Matlab can generate different file types. If Matlab generate .xlsx file, you have to specify it as .xlsx file.
There are a number of ways to read in data: readtable, readmatrix, importdata, ...
Dyuman Joshi
on 23 Nov 2023
"I used the extension .mat as it is a matlab generated file."
It does not matter how the file is generated, you have to provide the extension that is at the end of the file name.
Rahul
on 23 Nov 2023
hi,
now the code can detect the file but can't read the sub-file and its data (probably)
as it gives the error
Unable to resolve the name 'data1.variable.turbulence'.
Error in turb_speed (line 16)
speed_F(i,j)=sqrt(sigma_diff*data1.variable.turbulence(i,j)*mu_lmode^2)/(2*gamma_nonlin);
Here, I've attached the code as well as the data also. kindly advise.
clc;
clear all;
sigma_diff=0.5;
beta=0.01;
gamma_nonlin=2*beta;
i=100;
j=1;
speed_F=zeros(i,j);
mu_lmode=importdata('D:\Rahul\Data_tokamak\data&plot\data1_non-ctrw\L-mode data from L-mode eqn\data without edge source\Fisher model\data1.mat');
for j=1:100
speed_F(i,j)=sqrt(sigma_diff*data1.variable.turbulence(i,j)*mu_lmode^2)/(2*gamma_nonlin);
end
Avoid IMPORTDATA.
Use LOAD for MAT files:
F = './data1.mat';
S = load(F)
S = struct with fields:
data: [1×1 struct]
S.data.variable.turbulence
ans = 100×100
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
-0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
-0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0627 0.0640 0.0676 0.0727 0.0787 0.0850 0.0910 0.0967 0.1018 0.1062 0.1099 0.1129 0.1150 0.1164 0.1171 0.1169 0.1161 0.1145 0.1122 0.1093 0.1057 0.1014 0.0966 0.0911 0.0851 0.0785 0.0714 0.0638 0.0557 0.0471
0.0059 0.0065 0.0080 0.0099 0.0119 0.0138 0.0155 0.0169 0.0182 0.0191 0.0198 0.0203 0.0206 0.0207 0.0207 0.0206 0.0204 0.0201 0.0198 0.0195 0.0192 0.0189 0.0186 0.0183 0.0180 0.0178 0.0175 0.0173 0.0170 0.0168
0.0021 0.0044 0.0077 0.0107 0.0135 0.0159 0.0179 0.0196 0.0209 0.0218 0.0223 0.0225 0.0224 0.0221 0.0215 0.0207 0.0198 0.0188 0.0177 0.0166 0.0154 0.0142 0.0131 0.0119 0.0109 0.0099 0.0090 0.0081 0.0074 0.0068
0.0032 0.0056 0.0093 0.0128 0.0161 0.0190 0.0216 0.0237 0.0255 0.0270 0.0281 0.0288 0.0293 0.0294 0.0294 0.0291 0.0287 0.0282 0.0275 0.0267 0.0259 0.0250 0.0241 0.0231 0.0221 0.0210 0.0200 0.0189 0.0178 0.0166
0.0036 0.0060 0.0099 0.0136 0.0171 0.0202 0.0230 0.0254 0.0274 0.0291 0.0304 0.0314 0.0321 0.0325 0.0327 0.0328 0.0326 0.0324 0.0320 0.0316 0.0310 0.0305 0.0299 0.0293 0.0286 0.0279 0.0273 0.0266 0.0259 0.0252
0.0039 0.0063 0.0103 0.0142 0.0178 0.0211 0.0240 0.0265 0.0287 0.0305 0.0320 0.0332 0.0340 0.0346 0.0350 0.0352 0.0352 0.0351 0.0349 0.0347 0.0343 0.0339 0.0335 0.0331 0.0326 0.0321 0.0316 0.0312 0.0307 0.0302
0.0042 0.0066 0.0107 0.0147 0.0184 0.0219 0.0250 0.0277 0.0300 0.0320 0.0336 0.0349 0.0359 0.0367 0.0373 0.0376 0.0378 0.0379 0.0379 0.0378 0.0376 0.0374 0.0372 0.0369 0.0366 0.0363 0.0360 0.0357 0.0354 0.0350
Rahul
on 23 Nov 2023
Thanks Stephen23
Hi,
I again have one error which shows
Index in position 1 exceeds array bounds. Index must not exceed 1.
Would help if someone please advise the correction for error I made in the code.
sigma_diff=0.5;
beta=0.01;
gamma_nonlin=2*beta;
i=100;
j=1;
t=linspace(0,10,100);
speed_F=zeros(i,j);
source=load('D:\Rahul\Data_tokamak\data&plot\data1_non-ctrw\L-mode data from L-mode eqn\data without edge source\Fisher model\data7_L0_sig5.0_f1.mat');
mu_lmode=source.data.variable.a5_term(100,:);
turb=source.data.variable.turbulence(100,:);
for j=1:100
speed_F=real(sqrt(sigma_diff*turb(i,j).^(1-beta).*mu_lmode(i,j)/(2*gamma_nonlin)));
end
with regards,
rc
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Tags
See Also
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)