How to get rid of The RPC server is unavailable Error?

27 ビュー (過去 30 日間)
Susan
Susan 2020 年 7 月 10 日
回答済み: Samuel Gray 2022 年 1 月 26 日
Hi everyone,
I have a main folder with 10 subfolders in it. Each subfolder has 200 subfolders within them. in each of these 200 subfolders, I have 4 .csv files. I created a loop that the code opens a subfolder, do what I want and then move to the next one as follows
D = 'C:\Users\....\Data\'
S1 = dir(fullfile(D,'*'));
N1 = setdiff({S1([S1.isdir]).name},{'.','..'});
A = {};
B = {};
C = {};
for kk = 1 : 10
kk
D1 = fullfile(D, N1{kk});
S2 = dir(fullfile(D1,'*'));
N2 = setdiff({S2([S2.isdir]).name},{'.','..'});
for ii = 1 : 200
ii
T1 = dir(fullfile(D1,N2{ii},'*'));
C = {T1(~[T1.isdir]).name};
for jj = 1 : numel(C)
if jj == 1
F = fullfile(D1,N2{ii},C{jj});
[n,~,~] = xlsread(F);
elseif jj == 2
F = fullfile(D1,N2{ii},C{jj});
m = csvread(F);
elseif jj == 3
F = fullfile(D1,N2{ii},C{jj});
p = csvread(F);
elseif jj == 4
F = fullfile(D1,N2{ii},C{jj});
q = csvread(F);
end
end
A{kk, ii} = complex(p, m);
B{kk, ii} = q(:,1) - q(1,1);
C{kk, ii} = n(2);
end
end
when I run the code, I've got the "RPC server is unavailable" error on kk=2, ii =21. However, when I check the code manualy for kk=2, ii =21 it works perfectly. Any idea how I can get rid of this error? How I can improve the code to run faster? Any input would be greatly appreciated.

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 10 日
I can think of three potential solutions:
  • put a pause after the xlsread(); or
  • instead of using xlsread() look in the file exchange for xlsread1(); or
  • switch to readtable() instead of xlsread(). Note that if you switch to readtable() then you can probably use it or readmatrix() instead of the csvread().
That is, I suspect that the connection to the excel server is not ready in time, so you either need to slow down access or use the excel server differently or avoid using the excel server.
  1 件のコメント
Susan
Susan 2020 年 7 月 10 日
Thank you so much for your reply! I put a pause after the xlsread for 3sec, i.e., pause(3). But it wasn't able to solve the issue.
However, when I switched to readtable instead of xlsread(), it works perfectly.
Thanks again for your help!

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

その他の回答 (1 件)

Samuel Gray
Samuel Gray 2022 年 1 月 26 日
https://www.mathworks.com/help/matlab/ref/comserver.html

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by