cp949 error occurred while using smop. how do i solve it? - visual-studio-code

I searched for smop cp949 on stackoverflow, but didn't get any results, so I'm posting a question.
Traceback (most recent call last):
File "C:\Users\avern.conda\envs\ML\lib\site-packages\smop\main.py", line 58, in main
buf = open(options.filename).read()
UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 2: illegal multibyte sequence
Errors: 1
clc; clear; close all;
refPath = 'D:\220119 Stroke Segmentation_transUnet\Walin\phoresults_CharSeg'; %'./[1] NeungUK';
savPath = 'D:\220104 Stroke Segmentation\wallin\Pho\classifiedChar3'; %./[3-5] Classification results(nuk)';
refPath = 'D:\programming\Stroke segmentation\TransUNet\data\sukbo_06_300\seg_chrpho2';
savPath = 'D:\programming\Stroke segmentation\TransUNet\data\sukbo_06_300\cls_chrpho3';
refPath = 'D:\programming\Stroke segmentation\TransUNet\data\sukbo_06_300\seg_chrpho2';
savPath = 'D:\programming\Stroke segmentation\TransUNet\data\sukbo_06_300\cls_chrpho3';
refPath = 'D:\programming\Stroke segmentation\TransUNet\data\neungumgyoung_08_600\seg_chrpho';
savPath = 'D:\programming\Stroke segmentation\TransUNet\data\neungumgyoung_08_600\cls_chrpho';
load('net_checkpoint_220124_jamo_ep20.mat','net')
dirImage = dir( fullfile( refPath, '*.png' ));
group_labels = [];
jaumCode = string([ '1100';'1101';'1102';'1103';'1104';'1105';'1106';'1107';'1108';'1109';'110A';...
'110B';'110C';'110D';'110E';'110F';'1110';'1111';'1112';'1115';'111A';'111D';'1120';...
'1121';'1122';'1123';'1127';'112B';'112D';'112F';'1132';'1140';'1145';'1147';'114C';...
'1158';'1159';'115B';'115C';'115D';'11B0';'11B1';'11B2';'11B3';'11B5';'11DD' ]);
moumCode = string([ '11A1';'116A';'116B';'116C';'116D';'116E';'116F';'119E';'1161';'1162';'1163';...
'1165';'1166';'1167';'1168';'1169';'1170';'1171';'1172';'1173';'1174';'1175';'1188';...
'1191';'1192';'1194';'D7C4';'D7C5' ]);
mkdir( fullfile( savPath, 'fail' ));
%%
for n = 1 : size( dirImage, 1 )
[ ~, name, ~ ] = fileparts( fullfile(refPath, dirImage(n).name ));
file = fullfile( dirImage(n).folder, dirImage(n).name );
img = imread( file );
initPho = img( :, :, 2 ) | img( :, :, 3 );
midPho = img( :, :, 1 ) | img( :, :, 3 );
finPho = img( :, :, 1 ) | img( :, :, 2 );
initPho = resize64_Pho(initPho);
midPho = resize64_Pho(midPho);
finPho = resize64_Pho(finPho);
initPred = classify(net, initPho);
midPred = classify(net, midPho);
finPred = classify(net, finPho);
label = join( string([ initPred, midPred, finPred ]), "" );
savdir = fullfile( savPath, label );
ja_Idx1 = find(moumCode == string(initPred));
ja_Idx2 = find(moumCode == string(finPred));
mo_Idx = find(jaumCode == string(midPred));
if ~isempty(ja_Idx1) || ~isempty(ja_Idx2) || ~isempty(mo_Idx)
imwrite( img, fullfile( savPath, 'fail', join([ name '.png' ],"" )), 'png')
else
if any( strcmp( label, group_labels ))
imwrite( img, fullfile( savdir, join([ name '.png' ],"" )), 'png' );
else
assert( ~exist( fullfile( savPath, label ), 'dir' ))
mkdir( fullfile( savPath, label ));
imwrite( img, fullfile( savdir, join([ name '.png' ],"" )), 'png' );
group_labels = vertcat( group_labels, label );
end
end
label = [];
if mod(n,1000)
continue
end
disp([num2str(n)])
end

Related

ValueError: 'attacks' is not in list

import json
i = 1
file_name = 'PolitiFact_Fake_' + str(i) + '-Webpage.json'
with open(file_name, 'r') as fp:
obj = json.load(fp)
text = obj['text']
length = len(text)
wordlist = text.split()
wordfreq = []
for w in wordlist:
wordfreq.append(wordlist.count(w))
lengthslova = len(wordlist)
wordfind = 'in'
indexword = wordlist.index(wordfind)
indexfreq = wordfreq[indexword]
findword = [wordfreq, wordlist]
findwordt = [[row[j] for row in findword] for j in range(lengthslova)]
wordfind = "attacks"
indexfreq = 0
if indexword != ValueError:
indexword = wordlist.index(wordfind)
indexfreq = wordfreq[indexword]
findword = [wordfind, indexfreq]
indexfreq = wordfreq[indexword]
findword = [wordfind, indexfreq]
print('The freq of word ' + str(wordfind) + ':', indexfreq)
else:
indexfreq = 0
findword = [wordfind, indexfreq]
print('The freq of word ' + str(wordfind) + ':', indexfreq)
I keep receiving this error:
ValueError: 'attacks' is not in list

How to combine several mat file in matlab

I have two mat files named databaseA.mat and datalabelB.mat which have different sizes, databaseA.mat is 8100 x 80 double and datalabelB.mat is 1 x 80 double. I need to combine them into one mat file but don't change their size. Actually I have combined them with the following code
ALoad = load( 'databaseA.mat' );
BLoad = load( 'datalabelB.mat' );
save( 'databaseAB.mat', 'ALoad' );
save( 'databaseAB.mat', 'BLoad', '-append' );
but result "struct" type data, whereas I don't desire it.
I have asked in other forum too, they suggested to use this following
ALoad = load( 'databaseA.mat' );
BLoad = load( 'datalabelB.mat' );
a = ALoad.a;
b = BLoad.b;
save( 'databaseAB.mat', 'a', 'b' );
but it gives me an error
Reference to non-existent field 'a'.
Error in combineAB (line 8)
a = ALoad.a;
Could you correct it? Thank you for your help.
maybe I missing something, can you not just do:
ALoad = load( 'databaseA.mat' );
BLoad = load( 'datalabelB.mat' );
save( 'databaseAB.mat', 'ALoad', 'BLoad');
or if you want to combine them:
ALoad = load( 'databaseA.mat' );
BLoad = load( 'datalabelB.mat' );
ABLoad = [ALoad;BLoad];
save( 'databaseAB.mat', 'ABLoad');

Ini file read and write + add new property + matlab [duplicate]

This question already has an answer here:
Property_value + matlab
(1 answer)
Closed 9 years ago.
How to read and write ini files: I want to add new property to an existing one. I want to write the ini file to temp file and finally add the new property to it. the new property will have head,name,desc, value and layout (like: line 1 & 3)
#---------------
# head
# --------------
[name]% type
# desc
value
fileData = [];
fh = fopen( fileName, 'r' ); % read handle
tname=tempname();
wfh =fopen(tname,'w'); % write handle
line = fgetl(fh);
val = '';
Prop ='';
type = '';
header = '';
desc= '';
while ischar(line)
if strcmpi(line(1),'#') && strcmpi(line(3),'=')
layout = line(2:end);
elseif strcmpi(line(1),'#')&& ~strcmpi(line(3),'=')
header = line(2:end);
else
Prop = regexp(line,{'\[*\w+\]\s*%\s*.*\s*'},'match');
[property data_type] = strtok(Prop,'%')
prop_p = property{1};% property_name
prop_per = regexprep(prop_p,{'\[','\]'},'');
prop = prop_per{1};
Dtype = data_type{1}; % datatype
dtype = strtrim(strrep(Dtype,'%',''));
DATA_type = dtype{1};
end
% How can i define filedname (prop) for the 'layout' and 'header' as they are found in lines before the actual'prop'.
% From command window
% Undefined variable prop.
% Error in ecco2511>add (line 212)
% fileData.(prop{1}).layout = layout;
desc = fgetl(fh); % description
desc = desc(1:end);
line = fgetl(fh);
val = line(1:end);
fileData.(prop).layout = layout;
fileData.(prop).header = header;
fileData.(prop).type = DATA_type;
fileData.(prop).desc = desc;
fileData.(prop).val = val;
line = fgetl(fh); % keep reading
end
if ~isfield( fileData, propName)
fileData.(propName).val = newVal;
fileData.(propName).type = datatype;
fileData.(propName).desc = description;
fileData.(propName).layout = layout;
fileData.(propName).header = header;
else
error ( 'property %s already exists, use set to change its value',propName );
end
fileData = orderfields( fileData );
propNames = fieldnames( fileData );
for ii = 1:numel( propNames )
fprintf(wfh,'%s\r',fileData.(propNames{ii}).layout);
fprintf(wfh,'\n');
fprintf(wfh,'%s\r',fileData.(propNames{ii}).header);
fprintf(wfh,'\n');
fprintf(wfh,'%s\r',fileData.(propNames{ii}).layout);
fprintf(wfh,'\n');
fprintf( wfh, '[%s]%s\r', (propNames{ii}),fileData.(propNames{ii}).type);
fprintf(wfh,'\n');
fprintf( wfh,'#%s\r',fileData.(propNames{ii}).desc);
fprintf(wfh,'\n');
fprintf( wfh,'%s\r',fileData.(propNames{ii}).val);
fprintf(wfh,'\n');
end
fclose(fh);
fclose(wfh);
[status,errmsg]= movefile(tname,fileName,'f');
Sounds like you need INI Config from MATLAB File Exchange. It will allow you to read, write, and modify INI style files. I have used it a number of times and it works quite well.

How to update txt file in matlab

I want to update a line in a txt file which contains property-values pairs, where a property is between square brackets and its value in the line below. This is an example file: On top of that i want to ignore the comment lines started with '#'. On the other hand what if i want to add comments to the comment line?
#===========================
#===========================
[system]
# comment
programming
#===========================
[information]
#
application
In this example, ´system´ is a property and ´programming´ its value. The same way, ´information´ is another property and ´application´ its value.
I want to call my function with a property-value pair and update the corresponding values in the txt file. Until now I have the following:
fh = fopen(filename,'r');
fh= fopen(filename,'w');
while ~feof
line = fgetl(fh);
if(line(1) == '[') && (line(end) == ']')
value = lower(line(2:end-1));
Then I will compare the 'value' with my input to check if it matches with property. If so I should update the next line with the new input. Finally I have to write to the original file.
For this sample txt how can I update the word 'programming' to 'system information'?
How about
function [] = updateFile( fileName, propName, newProbVal )
%
% update file fileName, replacing the value of propName with newPropVal
%
% all inputs are strings
%
rfh = fopen( fileName, 'r' ); % read handle
tname = tempname(); % temporary file name
wfh = fopen( tname, 'w' );
% read line by line
foundFlag = false;
line = fgetl( rfh );
while ischar(line)
if foundFlag
fprintf( wfh, '%s\r\n', newProbVal );
foundFlag = false;
else
fprintf( wfh, '%s\r\n', line );
end
tks = regexp( line, ['^\[',propName,'\]'] );
foundFlag = ~isempty(tks);
line = fgetl( rfh );
end
fclose( rfh );
fclose( wfh );
movefile( tname, fileName, 'f' ); % rename temp file name

Structures within fields

s = struct('field1',...
{
struct('a',num2cell(0 + 4*rand(5,1)),'b',num2cell(0 + 4*rand(5,1)),'c',0);...
struct('a',num2cell(0 + 4*rand(5,1)),'b',num2cell(0 + 4*rand(5,1)),'c',0)...
},...
'field2',...
{
struct('a',num2cell(0 + 4*rand(5,1)),'b',num2cell(0 + 4*rand(5,1)),'c',0);...
struct('a',num2cell(0 + 4*rand(5,1)),'b',num2cell(0 + 4*rand(5,1)),'c',0)...
}...
);
How can I loop over structures in each field to avoid listing every structure within a field?
How about
arrayfun( #( w ) structfun( #( x ) arrayfun( #( y ) structfun( #( z ) disp( z ), y ), x ), w ), s )
You can replace disp with whatever function you wish to apply...