using xlswrite inside a loop and an error when using mac - matlab

I am trying to use the xlswrite inside a loop to put the results in each iteration
my function is like this
xlswrite('results',results(1,i).A,'results',data);
I get the following errors,
Error using xlswrite (line 187)
An error occurred on data export in CSV format.
Error in myalgorithm (line 178)
xlswrite('results',results(1,i).A,'results',data);
Caused by:
Error using dlmwrite (line 112)
The input cell array cannot be converted to a matrix.
I am using Matlab 2015b and also I am using mac
I also tried to use csvwrite instead xlswrite but no success. is there any one who can help me with it?

Related

Matlab error while creating csv file from image set using imread and csvwrite

I want to convert a set of images into a csv file. I was working with Matlab and I need each row corresponding to one image. I tried to do it with the following code
I=imread(c{n});
csvwrite('C:\Users\HP\Desktop\test.csv',I(:).','-append'); % c{n} contains the name of image files to be taken
but I am getting the following error
Error using dlmwrite (line 112)
Invalid attribute tag: ,.
Error in csvwrite (line 42)
dlmwrite(filename, m, ',', r, c);
Error in Untitled (line 7)
csvwrite('C:\Users\HP\Desktop\test.csv',I(:).','-append');
but if I try to do it without the '-append' there is no error.
How to change the code such that it takes all the images at once and produces a csv file with the single execution of the code.
csvwrite is meant for writing comma separated values, so adding that ',' is wrong. Then you have put a dot('.') after I(:), which is also wrong. I think you should better use dlmwrite if you want to append the files. It would go like dlmwrite('C:\Users\HP\Desktop\test.csv',I(:)','-append') (since you want each image as one row, you need to transpose the array).
For using this on all images, start by reading all the images into a cell array & then you use cellfun(#(x) dlmwrite('C:\Users\HP\Desktop\test.csv',x(:)','-append'),a). Or for a much simpler version just run the lines in your code inside a for loop.

Converting .mat file to .csv file results in an error?

I've looked online and have done the following to convert a .mat file into a .csv file, but I keep seeing an error. This is what I've tried:
FileData = load('mydata.mat');
csvwrite('weights.csv', FileData);
However I keep seeing the following error in matlab:
Undefined function 'real' for input arguments of type 'struct'.
Error in dlmwrite (line 189)
str = sprintf('%.*g%+.*gi',precn,real(m(i,j)),precn,imag(m(i,j)));
Error in csvwrite (line 42)
dlmwrite(filename, m, ',', r, c);
Here's a bit more information about my mat file
Would appreciate some help!
csvwrite works with matrices, not struct. You need to convert the struct into a matrix first.
Alternatively, if you're using newer versions of MATLAB and your struct members are all data arrays, you can also use T = struct2table(FileData) and then writetable(T,'myData.csv','Delimiter',',')

MatLab 2014a Fuzzy Toolbox Error

I am trying to devise a Sugeno fuzzy system using the fuzzy GUI - for some reason when I add more than one output variable I get errors:
Error using length
Too many input arguments.
Error in addvar (line 76)
for ct=1:length(out.output.mf)
Error in fuzzy (line 746)
fis=addvar(fis,varType,'',[0 1],'init');
Error while evaluating uimenu Callback
I'm using 2014a on a Mac running Mavericks. To note, I also have 2013a installed on a MacBook and tried adding the same input and output variables and I get them same error messages.
If you add more than one output variable, then try and add input variable the above messages are then displayed within the command prompt.

Read video using VideoReader function in Matlab?

I want to read a video from a folder and extract the frames from it.I used VidoeReader function.But it gives error.My code is shown below along with the error.
mov=VideoReader('11.mp4');
vidFrames=read(mov);
nFrames=mov.NumberOfFrames;
for i=1:nFrames
imshow(vidFrames(:,:,i),[]);
end
and the error show is as given below
Error using VideoReader/init
The file does not appear to have any video
data.
Error in VideoReader (line 147)
obj.init(fileName);
Error in video (line 7)
mov=VideoReader('11.mp4');
I think this is a MATLAB version related problem. I faced the same problem when I was using MATLAB 2013a. However, when I changed to MATLAB 2014b the problem just disappeared.

Error using parallel_function (matlabpool & parfor)

I want to read a large amount of files, process each of them and save the results for each of them in a .mat file. The processing of each file is independent from the others, so I'd like to try using parfor. I have written the following Matlab script file:
load filelist
obj = package.name.SomeObject();
matlabpool local 5
parfor i=1:length(filelist)
result = obj.compute(filelist{i});
[~, name, ~] = fileparts(filelist{i});
save(['~/path/' name], 'result');
end % file loop
matlabpool close
When I try to run it on my computer, a Matlab pool is intialized (connected to 5 workers), but then the following error message occurs:
Error using parallel_function (line 589)
Undefined function or variable "cleaner".
Error in readfiles (line 14)
parfor i=1:length(filelist)
Error in run (line 64)
evalin('caller', [script ';']);
Do you know where the problem could be?
I don't know why (there might be a connection to this issue), but the problem was solved by enclosing the code inside a function and calling that function (instead of calling the script file by run script.m). It also required creating a parsave function (see explanation here).