フィルターのクリア

Passing a file by function

4 ビュー (過去 30 日間)
SHAMA NOREEN
SHAMA NOREEN 2022 年 4 月 28 日
回答済み: Walter Roberson 2022 年 4 月 28 日
I am trying to send a file by function. I have two functions. The contents are as follows :
%%%SNR.m %%%%
%main
clear all
clc
noise_vec=0.5;
power_subch=[1 1 1 1 1 1 1 1 1 1 ];
H_k=randn(1,10);
Nof_Subcarriers=10;
aver_power=1;
sFileName = 'new.txt';
fid = fopen(sFileName,'wt');
gSNR=Gav(noise_vec, power_subch,aver_power, H_k,Nof_Subcarriers,fid)
fprintf(fid,'%f\n',gSNR);
func2(sFileName);
In this file I am calculating a value gSNR storing it and passing it to another file called func2.m
function func2(filenames)
headerLength=1;
numColumns=1;
fid = fopen(filenames ,'wt');
data = textscan(fid, repmat('%f',1,numColumns), 'headerlines', headerLength);
end
However there are are errors such as unable to read any data from file. TEXTSCAN might not have read access.
error in line : data = textscan(fid, repmat('%f',1,numColumns), 'headerlines', headerLength);
and in line : func2(sFileName);
I am not sure how to address these errors, have tried a lot.

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 4 月 28 日
fid = fopen(filenames ,'wt');
You opened the file for writing, but you immediately try to read it.
Note that you fail to close the file after.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by